Load | R Documentation |
This function restores a user-specified subset of the variables in an RDA file. It also allows one to remap the variables names in the RDA file to different variables names when restoring the objects. By default, it avoids overwriting existing variables. It returns the names of the loaded variables without making them invisible().
This is a drop-in replacement for load
,
with the first three arguments being passed directly to load
.
This version currently restores all the objects in the RDA file into a temporary environment and then assigning only the ones of interest to the target environment, discarding the other variables. So this is a helper function. The Table-of-Contents (RDAToc) approach allows us to restore just the variables of interest, but with a caveat of not yet fully handling reference objects in the RDA.
Load(file, envir = parent.frame(), verbose = FALSE, vars = character(), .noOverwrite = TRUE)
file |
the path to the RDA file, or a connection |
envir |
the environment into which the objects will be assigned/loaded |
verbose |
should item names be printed during loading? |
vars |
a character vector of variable names identifying the variables in the RDA file to restore/load.
The elements of this character vector can have a name, e.g., |
.noOverwrite |
a logical value that controls whether to overwrite any existing variables in
|
This current calls load
and then copies the subset of objects to envir
.
a character vector which is the subset of the combination of vars
and ...
for which the assignment took place.
Duncan Temple Lang
load
# Create a simple RDA file.
rda = tempfile()
a = 1:10
b = letters[1:5]
d = mtcars
save(a, b, d, file = rda)
# load a and b into a new environment and also ask for non-existent f
e = new.env()
Load(rda, e, vars = c("a", xyz = "b", "f"))
# result shows a and xyz=b, but no f.
# do it again and we won't overwrite
Load(rda, e, vars = c("a", xyz = "b"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.