[R] is it safe to replace every "<-" by "=" in R code?

Charilaos Skiadas cskiadas at gmail.com
Mon Jan 14 04:58:37 CET 2008


And of course let's not forget that a particularly twisted individual  
could overwrite "=":

 > `=` <- function(x,y) print(x+y)
 > 3 = 4
[1] 7
 > 3 <- 4
Error in 3 <- 4 : invalid (do_set) left-hand side to assignment


I also was for a while mystified by the <- assignment, and preferred  
= instead, but have since grown out of it, and now find <- more clear  
(especially since it makes the separation between function arguments  
and assignments clear).

I now have a problem whenever I switch to another programming  
language ....

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Jan 13, 2008, at 10:25 PM, S Ellison wrote:

> .. and don't forget that 6 -> x works but 6 = x won't ...
>
>>>> "Gabor Grothendieck" <ggrothendieck at gmail.com> 01/13/08 10:50 PM  
>>>> >>>
> No.
>
>> f <- function(a = 3, b = 4) a-b
>> f(b = 10)
> [1] -7
>> f(b <- 10)
> [1] 6
>
> but if you only replace it in the context:
>
> x <- ...
>
> then it should be ok.
>
> On Jan 13, 2008 5:41 PM, Nasser Abbasi <nma at 12000.org> wrote:
>> hi;
>>
>> When I first started looking at R code, I thought that the <-  
>> notation
> for
>> assignment made the code less readable (and I still do).  Then I  
>> found
> that
>> now one can use "=" in place of "<-" for assignment (I understand  
>> this
>> started since version 1.4). Anyway, I think using "=" makes the code
> much
>> more readable.
>>
>> I was wondering, would it be safe if I replace all the occurrences of
> "<-"
>> by "=" in any function of R? Or do you think this will break things?
>>
>> I like to look at a pretty code, and I just can't stand looking at
> those
>> "<-" any more :)
>>
>> I am using latest version of R on windoz platform.
>>
>> thanks
>> Nasser
>>




More information about the R-help mailing list