# [R] Is = now the same as <- in assigning values

Duncan Murdoch murdoch at stats.uwo.ca
Thu Dec 18 16:40:03 CET 2008

```On 12/18/2008 10:13 AM, Kenn Konstabel wrote:
> Hi,
>
> On Tue, Dec 16, 2008 at 9:13 AM, Wacek Kusnierczyk <
> Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
>
>> ... but this is also legal if you really hate <- :
>>
>> foo({x = 2})
>> # assign to x, pass to foo as a
>>
>
> This is legal but doesn't do what you probably expect -- although
> documentation for `<-` says the value (returned by <-) is 'value' i.e.
> whatever is on the right side ...
>
>> x<-NULL  # just to make sure it's not yet 42
>> foo <- function(a) a
>> foo({x = 42})   # no result
>> x
> [1] 42

All of x = 42, x <- 42, foo({x = 42}) and foo(x <- 42) do return 42, but
they do it "invisibly", so it won't print.  So "no result" isn't quite
right...

Duncan Murdoch

>
> If you really hate <-, you should do either
> foo({(x=42)})   # or ....
> foo({x=42; x})  # or even ...
> foo(a=force(x=43))
>
> As for = being more intuitive, my favorite example is x=x+1 (how on earth
> can x equal x+1 ??? ... wait, this is an assignment ¤#§£\$@{{!!!).
>
> KK
>
> 	[[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help