Besides some examples, such as system.time
, as others have shown, where <-
and =
have different results, the main difference is more philosophical. Larry Wall, the creator of Perl, said something like “similar things should look the same, different things should look different”, I found it interesting in different languages to see that things are considered “similar” and which are considered “ similar, "different." Now, to assign R, you can compare 2 commands:
myfun( a <- 1:10 ) myfun( a = 1:10 )
Some argue that in both cases we assign 1:10
to a
, so we do the same.
Another argument is that in the first call, we assign the variable a
, which is in the same environment from which myfun
is myfun
, and in the second call, we assign the variable a
, which is in the environment created when the function is called and is local to the function , and those two variables a
are different.
So what to use depends on whether you think the assignments are "similar" or "different."
Personally, I prefer <-
, but I don’t think it’s worth fighting the holy war.
source share