pass_baton: Pass a baton

View source: R/transfer.R

pass_batonR Documentation

Pass a baton

Description

Baton pass operation (write to contents, update metadata, append to YAML)

Usage

pass_baton(baton, content = list(), relocate)

Arguments

baton

R object of S3 class, created by create_baton.

content

a list of custom content that the baton should carry. Populates the YAML.

relocate

character vector defining the file path to move the YAML file upon completion of the pass.

Value

S3 class object.

Examples

## Not run: 
# ----------------------------------------- #
# The following code provides an example of how
# to create a baton, populate its content, and
# complete the pass.
# ----------------------------------------- #

# Define location where raw data lives (to be moved to bundle for snapshot)
raw_loc <- '/path/to/relay/raw'

# Create baton, within a bundle
baton_raw <- create_baton(bundled = TRUE,
                          bundle_params = list(dir = '/path/to/relay/raw_bundle',
                          tree = c('raw', 'processed', 'metadata', 'output')))

# Location of bundle
bundle_raw_loc <- dirname(baton_raw$metadata$location)


# Data expected to be used in bundle
data_manifest <- c("cdom_data_raw.Rds", "cases_imm.sas7bdat", "covid_comorbidity_lookup.sas7bdat",

# Move data to bundle
copy_files(raw_loc, data_manifest, file.path(bundle_raw_loc, 'raw'))

# Define content of baton to save to YAML in addition to metadata (nested lists)
existence <- map_lgl(data_manifest, ~file.exists(paste0(bundle_raw_loc, '/raw/', .))
creation_times <- map_chr(data_manifest, ~as.character(file.info(paste0(bundle_raw_loc, '/raw/', .))$mtime))
baton_content <- list(datasets = list(names = data_manifest,
                                      existence = existence,
                                      creation_times = creation_times))

# Pass baton for end of process (next step in the relay in another script can see if this baton was passed and, if so, the content it has)
baton_raw <- relay::pass_baton(baton_raw, content = baton_content)

## End(Not run)

al-obrien/relay documentation built on May 6, 2023, 10:19 p.m.