From lachmann at eva.mpg.de  Thu Apr 26 17:59:51 2012
From: lachmann at eva.mpg.de (ghostwheel)
Date: Thu, 26 Apr 2012 08:59:51 -0700 (PDT)
Subject: [Rd] delayedAssign changing values
In-Reply-To: <ED11A19C-0066-4D2C-845C-C41747A94BF5@r-project.org>
References: <17B09E7789D3104E8F5EEB0582A8D66FCD1EAC8145@MSGRTPCCRF2WIN.DMN1.FMR.COM>
	<ED11A19C-0066-4D2C-845C-C41747A94BF5@r-project.org>
Message-ID: <1335455991422-4590242.post@n4.nabble.com>

It is really strange that the delayedAssign is evaluated in the environment
it is called from, 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....

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.



[Rd] delayedAssign changing values
ghostwheel