In R, load(file = "file.Rdata")
will load all the variables as global variables. Is it possible to load all the variables contained in the .Rdata file into a list, so that it won't spoil the global variable space?
You could assign it to a new environment and from there convert it into a list:
load("file.Rdata", temp_env <- new.env())
env_list <- as.list(temp_env)
Using load
inside mget
with other envir=
onment than the .GlobalEnv
.
d1 <- d2 <- d3 <- d4 <- data.frame()
save(d1, d2, d3, d4, file="test.rda")
rm(d1, d2, d3, d4)
x <- mget(load("test.rda", envir=(NE. <- new.env())), envir=NE.)
ls()
# [1] "NE." "x"
x
# $d1
# data frame with 0 columns and 0 rows
#
# $d2
# data frame with 0 columns and 0 rows
#
# $d3
# data frame with 0 columns and 0 rows
#
# $d4
# data frame with 0 columns and 0 rows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With