access parametrically values of variables inside environments

Posted by Apostolos on Stack Overflow See other posts from Stack Overflow or by Apostolos
Published on 2012-07-09T09:07:25Z Indexed on 2012/07/09 9:15 UTC
Read the original article Hit count: 119

Filed under:

Let's say we have one or more environments and variables in them. My question is how we access the values of these variables, parametrically.

rm(list = ls())

env1 <- new.env()
env1$var1 <- "value1"

env2 <- new.env()
env2$var2 <- "value2"

env <- ls.str(mode="environment")        # We get the environments

var <- ls.str(eval(parse(text = env[1])))# We get the variables of an environment

eval(var[1])                             # We fail to get the value of a variable

Thank you all, in advance

© Stack Overflow or respective owner

Related posts about r