Re: [Rd] delayedAssign changing values

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Thu, 26 Apr 2012 12:53:42 -0400

On Apr 26, 2012, at 11:59 AM, ghostwheel wrote:

> It is really strange that the delayedAssign is evaluated in the environment it is called from,

Not quite, it is evaluated in the environment you specify - and you have control over both environments ... see ?delayedAssign

> and thus can have side effects.
> so
> x=2
> y=3
> delayedAssign("x", {y <- 7; y+3})
>
> gives

>> x

> [1] 10
>> y

> [1] 7
>
> Both x and y changed.
> More intuitive would have been the behavior
> x=2
> y=3
> delayedAssign("x", local({y <- 7; y+3}) )
>> x

> [1] 10
>> y

> [1] 3
> which only changes x.
> Or, at least that should be the default behavior....
>

That is questionable - I think it is more logical for both environments to be the same as default. Just think if it -- the point here is to access lazy evaluation which is exactly what it does - lazy evaluation takes place in the original environment, not in another one.

Cheers,
Simon

> Michael
>
> --
> View this message in context: http://r.789695.n4.nabble.com/delayedAssign-changing-values-tp4588108p4590242.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 26 Apr 2012 - 16:56:35 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 26 Apr 2012 - 23:50:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive