assignAndSaveData: Assign and save data

View source: R/assignAndSaveData.R

assignAndSaveDataR Documentation

Assign and save data

Description

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

Usage

assignAndSaveData(
  name,
  object,
  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),
  envir = parent.frame()
)

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

envir

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

Value

Invisible named character(1). File path.

Note

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

Updated 2022-06-02.

Examples

x <- 1L
dir <- AcidBase::tempdir2()
assignAndSaveData(
    name = "example",
    object = x,
    dir = dir,
    ext = "rds"
)
exists("example", inherits = FALSE)
file.exists(file.path(dir, "example.rds"))
AcidBase::unlink2(dir)

acidgenomics/pipette documentation built on Jan. 31, 2024, 10:32 p.m.