我正在查看R语言赋值运算符,并试图理解它们的工作原理,因此编写了以下代码:
> somevar1 <- "stuff1"
> "stuff2" -> somevar2
> somevar3 = "stuff3"
> "stuff4" <- somevar4
Error: object 'somevar4' not found
> "stuff5" = somevar5
Error: object 'somevar5' not found
> `<-`(somevar6, "stuff6")
> `=`(somevar7, "stuff7")
> `=`("stuff8", somevar8)
Error: object 'somevar8' not found
> `->`("stuff9", somevar9)
Error in `->`("stuff9", somevar9) : could not find function "->"
> `<<-`(somevar10, "stuff10")
> `->>`("stuff11", somevar11)
Error in `->>`("stuff11", somevar11) : could not find function "->>"
从代码开始到使用somevar9
时,一切都符合预期。但是我不明白为什么出现错误,如:Error in
->("stuff9", somevar9) : could not find function "->"
和Error in
->>("stuff11", somevar11) : could not find function "->>"
。难道->
和->>
操作符不需要存在吗?谢谢!
a -> b
时,它会调用'<-'("b", a)
,而当它遇到a ->> b
时,它会调用 `'<<-'("b", a)"。 - Allan Cameron:=
和_
。例如,可以使用没有%%
的中缀操作符。同样值得注意的是它们的优先级。 - Donald Seinen