Skip to content

advice/opinion on "<-" vs "=" in teaching R

2 messages · S Ellison, Thomas Lumley

#
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. 

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.

Steve Ellison



*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
#
On Mon, 18 Jan 2010, S Ellison wrote:

            
Evidence?(*)
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
tlumley at u.washington.edu	University of Washington, Seattle