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
--
Tam??s K. Papp
E-mail: tpapp at axelero.hu
Please try to send only (latin-2) plain text, not HTML or other garbage.
On Tue, 20 Apr 2004 15:39:07 +0200 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.If your objects are always called A, B, and C, the following should work: loadIntoList <- function(file) { load(file) return(list(A = A, B = B, C = C)) } hth, Z> 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 > > -- > Tam??s K. Papp > E-mail: tpapp at axelero.hu > Please try to send only (latin-2) plain text, not HTML or other > garbage. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
Try .saveRDS/.readRDS which enable you to save and load unnamed objects (in your case list(A, B, C)). On Tue, 20 Apr 2004, 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.-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595
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
>
Or maybe
loadIntoList <- function(filename) {
e <- new.env()
load(filename, envir = e)
mget(ls(e), envir = e)
}
-roger
Achim Zeileis wrote:> On Tue, 20 Apr 2004 15:39:07 +0200 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.
>
>
> If your objects are always called A, B, and C, the following should
> work:
>
> loadIntoList <- function(file) {
> load(file)
> return(list(A = A, B = B, C = C))
> }
>
> hth,
> Z
>
>
>>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
>>
>>--
>>Tam??s K. Papp
>>E-mail: tpapp at axelero.hu
>>Please try to send only (latin-2) plain text, not HTML or other
>>garbage.
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide!
>>http://www.R-project.org/posting-guide.html
>>
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
Delayed response (!) But perhaps more transparent than mget(ls(e), envir = e) is simply as.list(e) -roger Roger D. Peng wrote:> Or maybe > > loadIntoList <- function(filename) { > e <- new.env() > load(filename, envir = e) > mget(ls(e), envir = e) > } > > -roger > > Achim Zeileis wrote: > >> On Tue, 20 Apr 2004 15:39:07 +0200 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. >> >> >> >> If your objects are always called A, B, and C, the following should >> work: >> >> loadIntoList <- function(file) { >> load(file) >> return(list(A = A, B = B, C = C)) >> } >> >> hth, >> Z >> >> >>> 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 >>> >>> -- >>> Tam??s K. Papp >>> E-mail: tpapp at axelero.hu >>> Please try to send only (latin-2) plain text, not HTML or other >>> garbage. >>> >>> ______________________________________________ >>> R-help at stat.math.ethz.ch mailing list >>> https://www.stat.math.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide! >>> http://www.R-project.org/posting-guide.html >>> >> >> >> ______________________________________________ >> R-help at stat.math.ethz.ch mailing list >> https://www.stat.math.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide! >> http://www.R-project.org/posting-guide.html >> > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >