On Wed, Mar 7, 2012 at 11:51 AM, Mark Heckmann <mark.heckm...@gmx.de> wrote: > Hello, > > I have an empty environment named env. > Now I want the locally created objects in some function (foo) to appear in > env. > Within the function I want to have straight forward code, no assign operation > or env$x etc. in front of every command. > What is the best way to do that? > > Example: > > foo <- function(){ > x <- 1 > y <- 2 > } > env <- new.env() >
Try: foo <- function(){ x <- 1 y <- 2 environment() } e <- foo() or you could just forget about the function and do: e <- local({ x <- 1 y <- 2 environment() }) or e <- as.environment(list(x = 1, y = 2)) or library(proto) p <- proto(x = 1, y = 2) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.