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: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> CC: [EMAIL PROTECTED]
> 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@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@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.

Reply via email to