[R] loading into a list
Roger D. Peng
rpeng at jhsph.edu
Tue Apr 20 16:15:55 CEST 2004
I can think of two possible solutions. One is to load the .Rdata file
into an environment and then use the $ and [[ operators to access
elements.
> x <- 1; y <- 2
> save(x, y, file = "xy.RData")
> e <- new.env()
> load("xy.RData", envir = e)
> rm(x, y)
> e$x
[1] 1
> e$y
[1] 2
Another way, if you really want a list, is to load into an environment
(or the workspace) and use mget,
> e <- new.env()
> load("xy.RData", envir = e)
> mget(c("x", "y"), e)
$x
[1] 1
$y
[1] 2
Both of these only work in R >= 1.9.0.
-roger
Tamas Papp wrote:
> I have the following problem.
>
> Use the same algorithm (with different parameters) to generate
> simulation results. I store these in variables, eg A, B, C, which I
> save into a file with
>
> save(A, B, C, file="solution001.Rdata")
>
> I do this many times. Then I would like to load the above, but in
> such a manner that A, B, C woule be part of a list, eg
>
> sol001 <- loadIntoList("solution001.Rdata")
>
> so that sol001 is a list with elements A, B, C.
>
> I am looking for a way to implement the above function. The variables
> are very large and I need a lot of time to compute them, so saving &
> loading the results is the only viable alternative.
>
> Thanks,
>
> Tamas
>
More information about the R-help
mailing list