saveData: Save data

View source: R/saveData.R

saveDataR Documentation

Save data

Description

Wrapper for save() supporting quick, interactive saving of object names passed as symbols.

Usage

saveData(
  ...,
  dir = getOption(x = "acid.save.dir", default = getwd()),
  ext = getOption(x = "acid.save.ext", default = "rds"),
  overwrite = getOption(x = "acid.overwrite", default = TRUE),
  compress = getOption(x = "acid.save.compress", default = TRUE),
  list = NULL,
  envir = parent.frame()
)

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 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.

list

character. A character vector containing the names of objects to be saved. Note that this approach differs from save() 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 by envir. argument.

envir

environment. Environment.

Details

This function always saves each object into a separate file rather than combining multiple objects into a single file.

Value

Invisible named character. File paths.

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.

See Also

  • save().

  • saveRDS().

Examples

dir <- AcidBase::tempdir2()

## Interactive mode ====
## Note that this method uses non-standard evaluation.
a <- 1
b <- 2
saveData(a, b, dir = dir)
sort(list.files(dir))

## 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)
sort(list.files(dir))

## Clean up.
AcidBase::unlink2(dir)

steinbaugh/brio documentation built on Feb. 1, 2024, 6:42 p.m.