Assigns a new object by name to the current working environment then saves the newly assigned object, specified by the "dir" argument.

assignAndSaveData(name, object, envir = parent.frame(),
  dir = getOption("acid.save.dir", default = "."),
  ext = getOption("acid.save.ext", default = c("rds", "rda")),
  overwrite = getOption("acid.overwrite", default = TRUE),
  compress = getOption("acid.save.compress", default = TRUE))

Arguments

name

character(1). Desired variable name.

object

Object.

envir

environment. Environment to use for assignment. Defaults to parent.frame(), the calling environment.

dir

character(1). Directory path.

ext

character(1). R data serialized (RDS) or R data (RDA, RDATA). 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) or character(1). These character strings are currently allowed for save(): "gzip", "bzip2", or "xz".

Value

Invisible named character(1). File path.

Note

This function attempts to follow the same order as assign().

Updated 2019-07-19.

Examples

x <- 1L assignAndSaveData( name = "example", object = x, dir = ".", ext = "rds" )
#> Saving example.rds to /Users/mike/git/packages/brio/docs/reference.
exists("example", inherits = FALSE)
#> [1] TRUE
file.exists("example.rds")
#> [1] TRUE
## Clean up. rm(example) unlink("example.rds")