[R] use object within rda file in for loop

Ivan Calandra ivan.calandra at uni-hamburg.de
Thu May 20 15:06:05 CEST 2010

I've found the answer:
get() is exactly what I need, I completely forgot about this function.

There might be a better way, but that works for me.

Le 5/20/2010 14:13, Ivan Calandra a écrit :
> Dear users,
> I would like to process all the lists from all *.rda files that I have 
> in one folder.
> Up to now, I can load all the *.rda files without any problem.
> The problem is when I want to access the list saved within each *.rda 
> file (only one list per rda file).
> Here is my code:
> fpath <- "D:/R"
> listnames <- list.files(path=fpath, pattern=glob2rx("*.rda"), 
> full.names=FALSE)
> for (i in 1:length(listnames)) {
>   load(paste(fpath, listnames[i], sep="/"))
>   z <- list_in_listnames[i]  ## here is my problem
>   **do something on z**
> }
> It might be really simple, but listnames is a character vector and I 
> cannot find how to store the values within each element into z.
> I think there would be a function to get and use an object with a 
> given pattern in its name. The pattern itself is no problem, the 
> problem is the function.
> I've tried to look on RSiteSearch but, probably because I couldn't 
> figure out the keywords, haven't found anything helpful.
> Maybe I'm just on the wrong path to do it or missed something obvious...
> I hope my question is clear. If not, please let me know what would 
> help you to understand.
> Thanks in advance
> Ivan

PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de


More information about the R-help mailing list