Why are = and <- not equivalent inside ()?

 > within( list(a="a",b="b"), c="c" ) Error in eval(expr, envir, enclos) : argument is missing, with no default > within( list(a="a",b="b"), c<-"c" ) $a [1] "a" $b [1] "b" $c [1] "c" 

I'm not sure why exactly these two should not be equivalent. It seems that version = interpreted as an argument named c from the inside due to ... Is there any way to disable this behavior? I tried,

 within( list(a="a",b="b"), `c`="c" ) 

but it doesn’t work either.

+6
source share
2 answers

You are correct that c="c" (or any sentence of this form) is interpreted as an argument provided. And no, there is no way to disable this - it is supposedly being processed at the parser level R.

<- this difference between = and <- documented ?"<-"

The operators '& and' = are assigned to the environment in which they are evaluated. The operator '<- can be used anywhere, while the operator' = is allowed only at the top level (for example, in the full expression entered on the command line) or as one subexpression in the extended list of expressions.

The first example of a “copied expression list” is the body of a function, which you can check by typing, for example. is(body(plot.default)) , length(body(plot.default)) .

+8
source

Josh answered “why,” but there’s another “here” in the OP sentence:

 within( list(a="a",b="b"), "="(c,"c") ) # $a # [1] "a" # # $b # [1] "b" # # $c # [1] "c" 
+3
source

Source: https://habr.com/ru/post/944910/


All Articles