> 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 exactly why these two shouldn't be equivalent. It seems like the the =
version getting interpreted as an argument named c
to within because of the ...
. Is there any way to disable this behavior? I tried,
within( list(a="a",b="b"), `c`="c" )
but that fails too.
The operators <- and = assign into the environment in which they are evaluated. 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.
<- is assign operator in R. it can assign a value to a name. x <- 1. 1 is assigned to variable x.
"=" is assignment,just like other language. <- is a operator only work with channel,it means put or get a message from a channel. channel is an important concept in go,especially in concurrent programming.
even though the equal sign is also allowed in R to do exactly the same thing when we assign a value to a variable. However, you might feel inconvenient because you need to type two characters to represent one symbol, which is different from many other programming languages.
You are correct that c="c"
(or any clause of that form) is getting interpreted as a supplied argument. And no, there's no way to disable that -- it's presumably handled down at the level of the R parser.
This difference between =
and <-
is documented ?"<-"
The operators ‘<-’ and ‘=’ assign into the environment in which they are evaluated. 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 prime example of a "braced list of expressions" is a function body, which you can verify by typing, e.g. is(body(plot.default))
, length(body(plot.default))
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With