3 ms·
It is sometimes possible to use = for assignment, though I don't understand when this is and is not allowed. Most people avoid the issue by always using the arr
by joe_the_user 17y ago
It is sometimes possible to use = for assignment, though I don't understand when this is and is not allowed. Most people avoid the issue by always using the arrow.
Somehow this does not seem like an auspicious starting statement!
- jacobolus 17y agoIn a couple of semesters writing medium-complexity R programs, I never had any problems using = for assignment. I'd recommend it, as it's much easier to type than <-, and looks more natural coming from a programming background.
- joe_the_user 17y agoYes, but do you know the rules for when this is or isn't allowed? I guess I come from a background of looking at big applications and finding points failure where someone did something that would "probably work" - ie, it works till you allocate 5 megs of memory or....
- hadley 17y agoThe rules are pretty simple. It works everywhere, except in a function call, where = is used for named parameters, not creating new variables.
- jacobolus 17y agoI think the issue is assignment in R is an expression rather than a statement (I think), but there are some other places where '=' gets used for different syntax, and you always use <- for assignment, even in those situations. For me, it doesn't come up, because as a Python programmer I've fully bought into the idea that assignment should be a statement, and so I don’t try to use it as an expression in code. If you’re used to Python, then you’ll be used to seeing "=" for both assignment and keyword function arguments, so there’s no real confusion. I've never had a problem, but again, I've never tried to write R libraries for public consumption, or hack on large chunks of existing R code, so YMMV.
- xtho 17y agoIIRC it has to do with the environment where the assignment takes place. Take a look at the language specs for details: http://cran.r-project.org/doc/manuals/R-lang.html http://cran.r-project.org/doc/manuals/R-lang.html especially: http://cran.r-project.org/doc/manuals/R-lang.html#Argument-evaluation http://cran.r-project.org/doc/manuals/R-lang.html#Argument-e...