loader {utilitiesR} | R Documentation |
This function loads an Rdata file and returns a list containing its contents. The advantage is that it doesn't clutter the global workspace.
loader(filename, names = NULL)
filename |
name of the Rdata file |
names |
optional, character vector of objects in the Rdata file to retrieve (leave out to retrieve everything). |
a LIST with names(lst)==names
, values being the
object from the Rdata file. No entry for those objects in
names
that were not found in the Rdata file.
# create some data to save a <- 1 b <- 2 save(a,b,file='ab.rda') # load them back obj <- loader('ab.rda') names(obj) # 'a', 'b' obj$a # '1' # example of looking for particular objects: look for 'a' and 'foo'. obj <- loader('ab.rda',names=c('a','foo')) names(obj) # 'a' (foo wasn't found) obj$a # 1 obj$foo # NULL (wasn't found) # Demonstrate that it doesn't clutter local workspace rm(list=ls()) a <- 'foobar' obj <- loader('ab.rda',names='a') obj$a # 1 a # 'foobar'