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

Thomas Lumley tlumley at u.washington.edu
Mon Jan 18 20:06:31 CET 2010


On Mon, 18 Jan 2010, S Ellison wrote:

>
>
>>>> Thomas Lumley <tlumley at 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
tlumley at u.washington.edu	University of Washington, Seattle



More information about the R-help mailing list