2 ms·
> also can use = sometimes too (and I think has different semantics) That’s a common misconception (even the official documentation is misleading). In reality
by klmr 9y ago
> also can use = sometimes too (and I think has different semantics)
That’s a common misconception (even the official documentation is misleading).
In reality, assignment `<-` and assignment `=` have the exact same semantics (except for precedence, and unless you redefine them, which you can). The confusion comes from the fact that the `=` symbol is syntactically overloaded: it is also used for named argument passing (`foo(x = 1)`). This leads people to falsely claim that, if you wanted to perform assignment in a function call (which occasionally makes sense in R), then you’d have to use `<-`. But this is false. You merely need to disambiguate the usage, e.g. with extra parentheses: `foo((x = 1))` works.
- nfoz 9y agoThat's a fantastic clarification, thanks for that!