1

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
goweon
  • 1,111
  • 10
  • 19

1 Answers1

4

Create a list from env and then use list2env

list2env(as.list(env), .GlobalEnv)

or equivalently as a pipeline

env |> as.list() |> list2env(.GlobalEnv)
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341