On Mon, 18 Jan 2010, S Ellison wrote:
Thomas Lumley <tlum...@u.washington.edu> 15/01/2010 16:07 >>>
Which should I use or does it matter, please?
I would say to use = if you are teaching people familiar with C or
Java, and to use <- otherwise.
Nothing like an option to induce polarisation!
'=' is used in at least two contexts in R, one of which does not imply
formal assignment.
'<-' (and the left-to-right version '->') only mean formal assignment.
It is nearly always better in teaching programming languages to teach
the unambiguous/'always safe' form first or only.
Evidence?(*)
Anyone who learns multiple languages should be able to cope with such a
small change in operator, and the rather important difference between
assignment, name/value pairing and logical equals that R makes explicit
is actually a useful indicator that they are genuinely different
things.
That could be taken as an argument to use = for binding (ie,making a new variable)
and <- for destructive assignment, since then the use of = would match what it
does in argument lists, and the genuinely different operations would be
distinguished by syntax. I don't think anyone does that.
I believe that the reason for introducing = as an option for assignment was in
fact to improve the readability of code for programmers of other languages.
-thomas
(*) I only said what I would do. You are making a general optimality claim.
Thomas Lumley Assoc. Professor, Biostatistics
tlum...@u.washington.edu University of Washington, Seattle
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.