gpt4 book ai didi

r - 为什么不应该在函数中使用 "="R 运算符?

转载 作者:行者123 更新时间:2023-12-04 13:07:20 26 4
gpt4 key购买 nike

The manual状态:

The operator ‘<-’ can be used anywhere, whereas the operator ‘=’ is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions.



The question here提及在函数调用中使用时的区别。但是在函数定义中,似乎可以正常工作:
a = function () 
{
b = 2
x <- 3
y <<- 4
}

a()
# (b and x are undefined here)

那么为什么手册提到 the operator ‘=’ is only allowed at the top level ??

language definition中没有关于它的任何内容(没有列出 = 运算符,多可惜!)

最佳答案

您引用的文字是 at the top level OR in a braced list of subexpressions .您在子表达式的花括号列表中使用它。这是允许的。

您必须不遗余力地找到既不在顶层也不在大括号内的表达式。这是一个。有时你想把赋值放在 try 块中:try( x <- f() )很好,但是 try( x = f(x) )不是——您需要更改赋值运算符或添加大括号。

关于r - 为什么不应该在函数中使用 "="R 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10949483/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com