load_data {worcs} | R Documentation |
Load WORCS project data
Description
Scans the WORCS project file for data that have been saved using
open_data
or closed_data
, and loads these data
into the global (working) environment. The function will load the original
data if available on the current system. If only a synthetic dataset is
available, this function loads the synthetic data.
The name of the object containing the data is derived from the file name by
removing the file extension, and, when applicable, the prefix
"synthetic_"
. Thus, both "data.csv"
and
"synthetic_data.csv"
will be loaded into an object called data
.
Usage
load_data(
worcs_directory = ".",
to_envir = TRUE,
envir = parent.frame(1),
verbose = TRUE,
use_metadata = TRUE
)
Arguments
worcs_directory |
Character, indicating the WORCS project directory from
which to load data. The default value |
to_envir |
Logical, indicating whether to load objects directly into
the environment, or return a |
envir |
The environment where the data should be loaded. The default
value |
verbose |
Logical. Whether or not to print status messages to the console. Default: TRUE |
use_metadata |
Logical. Whether or not to use the codebook and value labels and attempt to coerce the class and values of variables to those recorded therein. Default: TRUE |
Value
Returns a list invisibly. If to_envir = TRUE
, this list
contains the loaded data files. If to_envir = FALSE
, the list is
empty, and the loaded data files are attached directly to the global
environment.
Examples
test_dir <- file.path(tempdir(), "loaddata")
old_wd <- getwd()
dir.create(test_dir)
setwd(test_dir)
worcs:::write_worcsfile(".worcs")
df <- iris[1:5, ]
suppressWarnings(closed_data(df, codebook = NULL))
load_data()
data
rm("data")
file.remove("data.csv")
load_data()
data
setwd(old_wd)
unlink(test_dir, recursive = TRUE)