load_in_new_env: Load an R data file into a new environment

View source: R/rdata_io.R

load_in_new_envR Documentation

Load an R data file into a new environment

Description

Unlike load(), this function avoids polluting the global namespace by loading objects into separate environment.

Usage

load_in_new_env(file, envir = new.env(), ...)

Arguments

file

This argument has the same meaning as in load()

envir

If you pass an existing environment, objects will be loaded into that environment instead of a newly-created one, and this same environment will be returned.

...

Further arguments are passed to load().

Details

This function is useful for loading data files that potentially contain many objects with common names that might otherwise overwrite existing objects with the same name.

Value

An environment containing all the objects loaded from file.

See Also

save.image()

Examples


x <- 5
y <- 3
datafile <- tempfile(fileext = ".rda")
save(file = datafile, list = c("x", "y"))
rm(x,y)
loaded_vars <- load_in_new_env(datafile)
as.list(loaded_vars)


DarwinAwardWinner/rctutils documentation built on July 22, 2022, 5:19 a.m.