[R] the less-than-minus gotcha
Martin Maechler
maechler at lynne.stat.math.ethz.ch
Mon Feb 2 16:11:37 CET 2015
> All the more reason to use = instead of <-
Definitely not!
(As you were told, there are other drawbacks).
R does not have to look like C, it *is* different in many ways.
If you use a decent IDE for R, you get spaces around ' <- ' for
free: Both in ESS and in Rstudio, you can use "[Alt] -"
to produce the 4 characters ' <- '
{ [Alt] + "-") is called 'M--' in ESS / emacs which has even
more options for " <- " and is fully configurable in its key
bindings anyway. }
The '=' character has many uses in R and using ' <- '
for assignment makes the code "more expressive": It makes sense
to highlight the assignment op, but is a bit stupid to
highlight all "=" signs. Further it can be nicely marked up by
a real "left arrow" by e.g. the listings LaTeX
'listings' package, or the (oldish) 'a2ps' GNU software.
Further, assignment is not commutative, and hence,
there is a corresponding ` -> ` operator,
whereas the '=' is a commutative operator in mathematics, but
not when used as assignment op.
[ yes: "Flame war is on. I'll stop reading R-help for a while.."
;-) ;-) ]
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ben Bolker
> Sent: Monday, 2 February 2015 2:07p
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] the less-than-minus gotcha
> Mike Miller <mbmiller+l <at> gmail.com> writes:
> >
> > I've got to remember to use more spaces. Here's the basic problem:
> >
> > These are the same:
> >
> > v< 1
> > v<1
> >
> > But these are extremely different:
> >
> > v< -1
> > v<-1
> >
> This is indeed documented, in passing, in one of the pages you listed:
> http://tim-smith.us/arrgh/syntax.html
> Whitespace is meaningless, unless it isn't. Some parsing ambiguities
> are resolved by considering whitespace around operators. See and
> despair: x<-y (assignment) is parsed differently than x < -y (comparison)!
More information about the R-help
mailing list