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()
#> Error in vapply(X = X, FUN = FUN, FUN.VALUE = logical(1L), ..., USE.NAMES = useNames): formal argument "USE.NAMES" matched by multiple actual arguments
assignAndSaveData(
name = "example",
object = x,
dir = dir,
ext = "rds"
)
#> Error in stop(simpleError(message = msg, call = if (p) { sys.call(p)})): Assert failure.
#> [1] isCharacter(dir) is not TRUE.
#> Cause: `function` is not character.
exists("example", inherits = FALSE)
#> [1] FALSE
file.exists(file.path(dir, "example.rds"))
#> Error in file.path(dir, "example.rds"): cannot coerce type 'closure' to vector of type 'character'
AcidBase::unlink2(dir)
#> Error in file.exists(x): invalid 'file' argument