R赋值运算符:=的作用是什么? [英] What is the R assignment operator := for?
问题描述
通过深入研究R源代码(文件R-3.2.2/src/main/gram.y
行2836
至2852)
,我发现R分析器/令牌器认为:=
是LEFT_ASSIGNMENT
令牌.
By digging into R source code (file R-3.2.2/src/main/gram.y
lines 2836
to 2852)
I found that the R parser/tokenizer considers that :=
is a LEFT_ASSIGNMENT
token.
但是在R.3.2.2
中尝试将其用作赋值运算符时,
我有一个错误(无法找到:=
的函数...),但是正如您所看到的,R会将其视为类似<-
的赋值:
But when trying to use it as an assignment operator in R.3.2.2
,
I have an error (impossible to find function for :=
...) but as you can see R considers it as an assignment like <-
:
> myVar := 42
Erreur : impossible de trouver la fonction ":="
> :=
Erreur : unexpected assignment in ":="
> <-
Erreur : unexpected assignment in "<-"
是错误,还是需要从令牌生成器源代码中删除令牌:=
?
Is it a bug, or does the token :=
need to be removed from the tokenizer source code?
R中是否有关于:=
运算符的故事?
Is there a past story about :=
operator in R?
推荐答案
它是以前允许的赋值运算符,请参见本文来自约翰·钱伯斯(John Chambers)在2001年.
It was a previously allowed assignment operator, see this article from John Chambers in 2001.
R的开发版本现在允许编写一些作业 使用=运算符的C或Java样式.这增加了兼容性 使用S-Plus(以及C,Java和许多其他语言).
The development version of R now allows some assignments to be written C- or Java-style, using the = operator. This increases compatibility with S-Plus (as well as with C, Java, and many other languages).
所有先前允许的赋值运算符(<-,:=,_和<< ;-) 保持完全有效.
All the previously allowed assignment operators (<-, :=, _, and <<-) remain fully in effect.
似乎:=
功能不再存在,但是您可以像这样重新启用"该功能:
It seems the :=
function is no longer present, but you can "re-enable it" like this:
`:=` <- `<-`
x:=3
x
[1] 3
这篇关于R赋值运算符:=的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!