[R] Reading through a group of .RData files

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Dec 10 20:47:31 CET 2007

On Mon, 10 Dec 2007, Talbot Katz wrote:

> Hi.
> I have a procedure that reads a directory, loops through a set of 
> particular .RData files, loading each one, and feeding its object(s) 
> into a function, as follows:
> cvListFiles<-list.files(fnDir);
> for(i in grep(paste("^",pfnStub,".*\\.RData$",sep=""),cvListFiles)){
> load(paste(fnDir,cvListFiles[i],sep="/"));
> myFunction(rliObject);
> rm(rliObject);
> };
> where fnDir is the directory I'm reading, and pfnStub is a string that 
> begins the name of each of the files I want to load.  As you can see, 
> I'm assuming that each of the selected .RData files contains an object 
> named "rliObject" and I'm hoping that nothing in any of the files I'm 
> loading overwrites an object in my environment.  I'd like to clean this 
> up so that I can extract the object(s) from each data file, and feed 
> them to my function, whatever their names are, without corrupting my 
> environment.  I'd appreciate any assistance.  Thanks!

You can load() each to a new enviroment: see the arguments of load().

> --  TMK  --212-460-5430 home917-656-5351 cell
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list