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

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Wed Mar 11 20:20:06 CET 2009


Duncan Murdoch wrote:
>
> 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.

in fact, some recent posts show that things can go the other way round: 
people try to use <- for function arguments.  i think the following is
the most secure way if one really really has to do assignment in a
function call:

    f({a=3})

and if one keeps this convention, <- can be dropped altogether.

vQ




More information about the R-help mailing list