Skip to content
Prev 178298 / 398506 Next

Extracting an object name?

On 24/04/2009 9:30 PM, greggallen at gmail.com wrote:
predict() doesn't want an object name, it wants an object.  load() 
returns an object name, and loads the object.  So you can find the 
object by the name that gets loaded.

If the students only created one object, you could do it as

name <- load(s)
model <- get(name)

but that's dangerous:  if you don't know what the student named the 
model, then you don't want to load it in with all your other variables. 
  So a safer way to go is:

studentvars <- new.env()
names <- load(s, studentvars)

Now figure out which of the names is the model (say names[1]), and do
model <- get(names[1], envir=studentvars)

Duncan Murdoch