[R] How to set a former environment?

Gabor Grothendieck ggrothendieck at gmail.com
Mon Apr 3 20:08:01 CEST 2006

Here L is a list of environments and the lapply
creates z in each of them:

L <- list(e1 = new.env(), e2 = new.env())
junk <- lapply(L, function(e) e$z <- 1)
ls(L$e1) # "z"

You might also want to look at the proto package:

On 4/3/06, Werner Wernersen <pensterfuzzer at yahoo.de> wrote:
> Hi,
> I probably misunderstand the entire concept of
> environments in R. I now have a list of environments
> in which each has a number of variables. What I want
> to do is to apply a function on each of those
> environments which adds additional variables to that
> particular environment. Is there a way to set the
> environment of the function so that also the variables
> newly created in the function are added to the
> environment?
> Right now I do
> environment(FN) <- oldEnvironment
> before I call the function and the function operates
> on the old environments variables but the newly
> created ones are not in the old environment.
> Thank you for considering my question!
>  Werner
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

More information about the R-help mailing list