Skip to content

Loading an .RData file and assigning the loaded objects within a loop

1 message · Barry Rowlingson

#
Within lapply load the file and return the value of the thing or
things in the file you want. Something like this:

 > files
[1] "x1.RData" "x2.RData" "x3.RData" "x4.RData"

 > lapply(files,function(z){load(z);x})
[[1]]
[1] 1

[[2]]
[1] 22

[[3]]
[1] 333

[[4]]
[1] 4444

Each of my files contains a single number stored in an object called
'x'. Within the loop 'x' has the value just loaded from the file.

Another method is to use the environment argument of load to save into
an environment other than the global one...
On Sat, Jun 1, 2013 at 11:52 AM, Jim Holtman <jholtman at gmail.com> wrote: