3 ms·
In 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 th
by jacobolus 17y ago
In 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.