stow: Store an object (temporarily).

View source: R/transfer.R

stowR Documentation

Store an object (temporarily).

Description

stow will save an object from the R environment to a location on the hard-drive, preferably a temporary location (i.e. tempfile).

Usage

stow(
  object,
  path = NULL,
  new_name = NULL,
  method = c("rds", "fst", "qs", "csv"),
  compress = TRUE,
  cleanup = FALSE,
  envir = .GlobalEnv,
  ...
)

Arguments

object

Dataset from the R environment; if a list is being stowed, use the 'rds' method.

path

Character string, location to stow object on hard-drive, default is NULL and will be placed in a temporary location.

new_name

Character string that is used to name the temporary file; default is NULL and uses the object name.

method

Character string for method of export, either 'rds', 'fst', 'qs', 'csv'; used to determine the file extension.

compress

Logical value; default is TRUE, will compress the outputs.

cleanup

Logical value; default is FALSE, will remove the object from the provided environment.

envir

Location from which to export/cleanup the object of interest; default is .GlobalEnv.

...

Additinal arguments based to the write function of the respective method.

Details

This function will export an object to the hard-drive as a '.rds' or '.fst' file. As such, the 'fst' package is required for this function. Typically, the purpose of this is to remove a large objects (a few Giga-bytes) from the R session to reclaim RAM and to use retrieve at the exact time it is required later in a workflow. stow outputs an object of the S3 class that contains pertinent information on how to easily retrieve the object. It is recommended to name the output as the same as the object but appended with '_stowed'. The option to output as a 'csv' file is available to easily stow and pickup in non R workflows.

Value

S3 object of class stow_temp, to be used when retrieving data.

Examples

## Not run: 
# Create fake data
temp_data <- data.frame(col1 = rpois(100, 1), col2 = runif(100))

# Stow an object
temp_data_stowed <- stow(object = temp_data, method = 'fst', cleanup = TRUE)

# Retrieve an object
temp_data <- retrieve(stowed_object = temp_data_stowed, cleanup = TRUE)

## End(Not run)

al-obrien/farrago documentation built on April 14, 2023, 6:20 p.m.