[R] Is there any difference between <- and =

Duncan Murdoch murdoch at stats.uwo.ca
Wed Mar 11 15:52:06 CET 2009


On 3/11/2009 10:18 AM, Sean Zhang wrote:
> Dear R-helpers:
> 
> I have a question related to <- and =.
> 
> I saw very experienced R programmers use = rather than <- quite
> consistently.
> However, I heard from others that do not use = but always stick to <- when
> assigning valuese.
> 
> I personally like = because I was using Matabl, But, would like to receive
> expert opinion to avoid potential trouble.

Use <- for assignment, and = for function arguments.  Then the 
difference between

  f( a = 3 )
  f( a <- 3 )

is clear, and you won't be surprised that a gets changed in the second 
case.  If you use = for assignment, the two lines above will be written as

  f( a = 3 )
  f( ( a = 3 ) )

and it is very easy to miss the crucial difference between them.

Duncan Murdoch

> 
> Many thanks in advance.
> 
> -Sean
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list