Re: [R] Reading through a group of .RData files

From: Benilton Carvalho <bcarvalh_at_jhsph.edu>
Date: Tue, 11 Dec 2007 13:43:42 -0500

actually, the lapply() was supposed to be used with your particular function...

to remove, all you need is:

rm(list=myObj)

b

On Dec 11, 2007, at 1:42 PM, Talbot Katz wrote:

> Thanks again, Benilton, I found your suggestions very helpful. But
> I couldn't seem to use the lapply / get combination to remove the
> objects that were loaded. The best I could come up with was:
>
> eval( parse( text = paste( "rm(", paste( myObj, collapse = "," ),
> " )", sep = "" ) ) )
>
> I'm wondering whether there's a cleaner / easier way to remove a set
> of objects whose names are listed in a character array (as returned
> by load) ?
>
> Thank you!
>
> -- TMK --
> 212-460-5430 home
> 917-656-5351 cell
>
>
>
> > Date: Mon, 10 Dec 2007 14:31:19 -0500
> > From: bcarvalh_at_jhsph.edu
> > To: topkatz_at_msn.com
> > CC: r-help_at_stat.math.ethz.ch
> > Subject: Re: [R] Reading through a group of .RData files
> >
> > note that load() returns, invisibly, a string with the names of the
> > objects that were loaded. something in the lines of:
> >
> > myObj <- load(file.path(fnDir, cvListFiles[i]))
> > myFunction(get(myObj))
> > rm(list=myObj)
> >
> > might be closer to what you want.
> >
> > moreover, if length(myObj) > 1, you might want sth like:
> >
> > lapply(myObj, function(x) myFunction(get(x)))
> >
> > instead...
> >
> > best
> > b
> >
> > 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!
> > >
> > > -- 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.
> > >
>



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. Received on Tue 11 Dec 2007 - 18:46:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 11 Dec 2007 - 19:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.