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.save.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 or character string specifying whether saving to a named file is to use compression. TRUE corresponds to gzip compression, and character strings "gzip", "bzip2" or "xz" specify the type of compression. Ignored when file is a connection and for workspace format version 1.

Value

Invisible named character(1). File path.

Note

This function attempts to follow the same order as assign.

Examples

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