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.
TRUE
corresponds togzip
compression, and character strings"gzip"
,"bzip2"
or"xz"
specify the type of compression. Ignored whenfile
is 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()
## Interactive mode ====
## Note that this method uses non-standard evaluation.
a <- 1
b <- 2
saveData(a, b, dir = dir)
#> → Saving a.rds, b.rds to /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpX02vhQ/DI1Xbl9aUd-170267962530577.
sort(list.files(dir))
#> [1] "a.rds" "b.rds"
## Clean up.
AcidBase::unlink2(dir)
## 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)
#> → Saving a.rds, b.rds to /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpX02vhQ/DI1Xbl9aUd-170267962530577.
sort(list.files(dir))
#> [1] "a.rds" "b.rds"
## Clean up.
AcidBase::unlink2(dir)