[英]load .Rdata file into list()
In R, load(file = "file.Rdata")
will load all the variables as global variables.在 R 中, load(file = "file.Rdata")
将加载所有变量作为全局变量。 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?是否可以将.Rdata文件中包含的所有变量加载到一个列表中,这样就不会破坏全局变量空间?
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
.使用load
inside mget
和其他环境而.GlobalEnv
envir=
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.