Skip to content
Prev 39404 / 63424 Next

Create an environment and assign objects to it in one go?

Hi,

thanks to both of you.  My use case was actually to in-the-end create
a *list* in a cut'n'paste-friendly way, e.g.

env <- function(..., hash=FALSE, parent=parent.frame(), size=29L) {
  envir <- new.env(hash=hash, parent=parent, size=size);
  evalq(..., envir=envir);
? envir;
} # env()


x <- list();

x$case1 <- env({
  # Cut'n'pasted from elsewhere
  a <- 1;
  b <- 2;
});

x$case2 <- env({
  # Cut'n'pasted from elsewhere
  a <- 3;
  b <- 1;
});

x <- lapply(x, FUN=as.list);
List of 2
 $ case1:List of 2
  ..$ b: num 2
  ..$ a: num 1
 $ case2:List of 2
  ..$ b: num 1
  ..$ a: num 3

/Henrik


On Thu, Mar 10, 2011 at 5:53 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote: