Wrapper for save() supporting quick, interactive saving of object names
passed as symbols.
Arguments
- ...
Object names. Note that these arguments are interpreted as symbols using non-standard evaluation for convenience during interactive use, and must not be quoted.
- dir
character(1). Directory path.- ext
character(1). Output file format extension.Supported arguments:
"rds": R data serialized (RDS)."rda": R data (RDA).
RDS is preferred when saving single objects per file, which is always the convention of
saveData(), regardless of the extension used.- overwrite
logical(1). Overwrite existing file on disk.- compress
logical or character string specifying whether saving to a named file is to use compression.
TRUEcorresponds togzipcompression, and character strings"gzip","bzip2","xz"or"zstd"specify the type of compression. Ignored whenfileis a connection and for workspace format version 1.- list
character. A character vector containing the names of objects to be saved. Note that this approach differs fromsave()in that the objects are saved individually to disk, instead of inside a single R data file. Requires objects to be defined in environment specified byenvir. argument.- envir
environment. Environment.
Details
This function always saves each object into a separate file rather than combining multiple objects into a single file.
Note
This function is desired for interactive use and interprets object
names using non-standard evaluation. It will overwrite existing files
on disk, following the same conventions as save().
Updated 2023-06-29.
Examples
dir <- AcidBase::tempdir2()
#> Error in vapply(X = X, FUN = FUN, FUN.VALUE = logical(1L), ..., USE.NAMES = useNames): formal argument "USE.NAMES" matched by multiple actual arguments
## Interactive mode ====
## Note that this method uses non-standard evaluation.
a <- 1
b <- 2
saveData(a, b, dir = dir)
#> Error in stop(simpleError(message = msg, call = if (p) { sys.call(p)})): Assert failure.
#> [1] isString(dir) is not TRUE.
#> Cause: `function` is not character.
sort(list.files(dir))
#> Error in list.files(dir): invalid 'path' argument
## Clean up.
AcidBase::unlink2(dir)
#> Error in file.exists(x): invalid 'file' argument
## List mode ====
## Note that this method uses standard evaluation.
## Use this approach inside of functions.
a <- 1
b <- 2
list <- c("a", "b")
saveData(list = list, dir = dir)
#> Error in stop(simpleError(message = msg, call = if (p) { sys.call(p)})): Assert failure.
#> [1] isString(dir) is not TRUE.
#> Cause: `function` is not character.
sort(list.files(dir))
#> Error in list.files(dir): invalid 'path' argument
## Clean up.
AcidBase::unlink2(dir)
#> Error in file.exists(x): invalid 'file' argument