[R] assign / environment side effect on R 2.4.0

From: Thomas Petzoldt <Thomas.Petzoldt_at_TU-Dresden.de>
Date: Sat 24 Jun 2006 - 00:30:46 EST


I got several off-list answers to my question on R-Help:

"[R] list of interdependent functions" from 2006-06-20

and by evaluating this (and also my own example) I found differences in the behavior of older versions of R (R 2.2.1 and 2.3.1) and the most recent R 2.4. under development (SVN revision 38399, WinXP SP 2).

The example is a constructed cut-down example, but this behavior is observed also in different versions of the full implementation.

While in the older versions the environment of L$test remains R_Globalenv, a changed environment is returned under R 2.4.0

Ist this side effect a "bug" or a "feature"? The list(unlist(L)) workaround helps to avoid the side effect.


envfun <- function(L) {
  # L <- as.list(unlist(L)) # !!! workaround   p <- parent.frame()
  assign("test", L$test, p)
  environment(p[["test"]]) <- p

solver <- function(L) {
  # some other stuff

L <- list(test = function() 1 + 2)

e1 <- environment(L$test)
e2 <- environment(L$test)

# <environment: R_GlobalEnv>

# <environment: 0x01d0b088>

Thomas Petzoldt                    Tel. +49-351-463 3 4954
Technische Universitaet Dresden    Fax  +49-351-463 3 7108
Institut fuer Hydrobiologie        thomas.petzoldt@tu-dresden.de
01062 Dresden                      http://tu-dresden.de/hydrobiologie/

Upcoming: German Limnology Conference!    http://tu-dresden.de/dgl2006

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Jun 24 00:40:07 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 24 Jun 2006 - 02:12:31 EST.

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