[R] loading into a list

Seth Falcon sfalcon at fhcrc.org
Tue Apr 20 18:17:15 CEST 2004


On Tue, Apr 20, 2004 at 04:25:27PM +0200, Tamas Papp wrote:
> 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.
> }

This might be helpful...

loadIntoList <- function(file) {
  load(file)
  v <- list()
  for (i in ls()) {
      v[[i]] <- eval(as.name(i))
  }
}

The ls() may give you too much, however...

+ seth




More information about the R-help mailing list