Assigns a new object by name to the current working environment then saves
the newly assigned object, specified by the "dir"
argument.
Arguments
- name
character(1)
. Desired variable name.- object
Object.
- 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(1)
orcharacter(1)
. These character strings are currently allowed forsave()
:"gzip"
,"bzip2"
, or"xz"
.- envir
environment
. Environment to use for assignment. Defaults toparent.frame()
, the calling environment.
Examples
x <- 1L
dir <- AcidBase::tempdir2()
assignAndSaveData(
name = "example",
object = x,
dir = dir,
ext = "rds"
)
#> → Saving example.rds to /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpX02vhQ/ZYiChV7MTc-170267960652544.
exists("example", inherits = FALSE)
#> [1] TRUE
file.exists(file.path(dir, "example.rds"))
#> [1] TRUE
AcidBase::unlink2(dir)