[R] Looping through file names and loading...
murdoch at stats.uwo.ca
Thu Apr 16 00:22:16 CEST 2009
greggallen at gmail.com wrote:
> Dear R-Community:
> I am assisting a community college instructor in an introductory
> statistics class.
> He has asked me to do this:
> Read in a file, of filenames, line by line:
> Student_models.txt : (contains 1500+ filenames)
> function(filename)# I pass in filename
> for(i in 1:length(filename))
> s <- filename[i,1]
> print(s) # I check the file name, and it is OK.
> load(s) # This returns all sorts of errors, most common is: object
> "mod" not found.
Calling load(s) here will load the objects from a saved image into the
local evaluation frame of your function. They could overwrite i, or s,
or filename, or any other local variables. Are you sure that's what you
want to do? I think it would be safer to do something like
e <- new.env()
and then you've loaded things into e, not into your evaluation frame,
and they shouldn't mess you up. It makes it a bit more work to extract
things, but not that much more.
> pred <- predict( s , test_vector) # I never get this far
Now this doesn't make sense: isn't "s" a filename?
> write(filename, pred, "output.txt")
> The filenames are correct, and I can use "load(s)" interactively, but
> it won't work in a function.
> Thanks for ANY help!!!!
> Gregg Allen
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help