[R] loading into a list

Tamas Papp tpapp at axelero.hu
Tue Apr 20 16:25:27 CEST 2004


On Tue, Apr 20, 2004 at 03:57:13PM +0200, 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))
> }

Sorry for not mentioning that, but variables sometimes have different
names.  I am looking for something like this:

loadIntoList <- function(file) {
  load(file)
  v <- list()
  ## for each variable name 'i' in ls(), assign 
  ## v$i <- i
  ## but I don't know how to write this...  I need help in that.
}

Professor Ripley mentioned save/readRDS, I have looked into that but I
need the variable names too.

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.




More information about the R-help mailing list