[R] Is there any difference between <- and =
zaslavsk at hcp.med.harvard.edu
Fri Mar 13 15:25:19 CET 2009
I would argue that this is a matter of preference and the arguments on
"principle" for one side or another are not particularly compelling.
When the "=" was introduced for assignment, an argument was made that
name=value function arguments are also implicitly a kind of assignment.
While Duncan has pointed out a typical example of how this could be
ambiguous, <- also has its problems. A syntactic confusion with "<-"
arises in expressions like
which could be read either as an assignment or as a logical expression
comparing x to -3. Perhaps obviously ambiguous when written naked like
this but when buried in a larger expression, it's easy to write an
expression like that and discover that you have overwritten x. Some might
(and have, most emphatically) advise that we should routinely insert
spaces in our typing in a way that disambiguates such expressions but I
find an argument that relies on spaces, which are usually syntactically
unmeaningful, not very compelling.
Besides, I just find that clumsy two-character arrow ugly! This is an
esthetic matter -- reminds me too much of an emoticon. :-( For over 10
years I used the alternative "_" underscore for S assignment (nice as a
single character with no competing syntactic meaning) but that has gone
away, as far as I can tell primarily due to discomfort (disdain?) of
developers who find it unattractive because of the use of "_" as a
connecting special category in OTHER contexts (C and shell programming).
However, a mutually satisfactory solution is at hand!! If growth in the
number of R programmers continues exponentially at its current rate, by
the year 2097 the number of R programmers will exceed the population of
the earth. At that point they will rise up and demand the restoration of
the APL arrow key (remembered by some doddering guru who heard about it
from her grandfather) to the standard keyboard, and our problem will be
solved. (But there will be a minor irritation because in the New Zealand
keyboard that key code will have been assigned to the locally popular
More information about the R-help