英文:
"unpack" contents of an R environment object to current working environment
问题
assign("a", env$a)
assign("b", "bar")
assign("c", env$c)
英文:
I want to achieve an effect similar to saving and loading .RData
files like the following code, but without writing anything out to a file, and using environments instead.
a <- 1
c <- 3
save('a', 'c', file="file.RData")
a <- 'foo'
b <- 'bar'
load("file.RData")
So lets say I have some variables stored within an environment, some which share names of variables in the working environment
a <- 'foo'
b <- 'bar'
env <- new.env()
env$a <- 1
env$c <- 3
I want to unpack all the contents of env
into the current environment, possibly overwriting some variables, such that the final values of each variable are
a = 1
b = 'bar'
c = 3
答案1
得分: 4
从 env
创建一个列表,然后使用 list2env
list2env(as.list(env), .GlobalEnv)
或者等效地使用管道
env |> as.list() |> list2env(.GlobalEnv)
英文:
Create a list from env
and then use list2env
list2env(as.list(env), .GlobalEnv)
or equivalently as a pipeline
env |> as.list() |> list2env(.GlobalEnv)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论