TMS*_*TMS 6 r assignment-operator
手册说明:
运算符'< - '可以在任何地方使用,而运算符'='仅允许在顶层(例如,在命令提示符下键入的完整表达式中)或作为支撑表达式列表中的子表达式之一.
这里的问题提到了在函数调用中使用时的区别.但在函数定义中,它似乎正常工作:
a = function ()
{
b = 2
x <- 3
y <<- 4
}
a()
# (b and x are undefined here)
Run Code Online (Sandbox Code Playgroud)
那么为什么手册提到了the operator ‘=’ is only allowed at the top level?
在语言定义中没有任何关于它的内容(没有=列出运算符,真可惜!)
Vin*_*ynd 12
你引用的文字说at the top level OR in a braced list of subexpressions.您在子表达式的支撑列表中使用它.这是允许的.
你必须竭尽全力找到既不是顶部也不是括号内的表达.这是一个.你有时想在try块中包含一个赋值:try( x <- f() )很好,但try( x = f(x) )不是 - 你需要更改赋值运算符或添加大括号.
不在顶层的表达包括在控制结构中的使用if.例如,以下编程错误是非法的.
> if(x = 0) 1 else x
Error: syntax error
Run Code Online (Sandbox Code Playgroud)
如上所述:https://stackoverflow.com/a/4831793/210673
另请参阅http://developer.r-project.org/equalAssign.html
| 归档时间: |
|
| 查看次数: |
470 次 |
| 最近记录: |