A database repository may define post_export <- function(database, path) in R/post_export.R, for outputs derived from the finished database that are wanted only when it is published: a flattened copy, parquet files, other formats. No build runs it, so it adds nothing to a rebuild; it runs when this is called, from a repository's release script, or by build_export() after a targets build.

build_post_export(
  database,
  path = file.path("export", "data", "curr"),
  file = "R/post_export.R"
)

Arguments

database

Database object, as built by the pipeline

path

Directory post_export() should write into; created if missing

file

Path to the file defining post_export(). If the file does not exist, nothing is run.

Value

path, invisibly

Details

Processing that belongs in the database itself, applied on every build, goes in post_build() in R/post_build.R instead; see build_post_process(). post_export() cannot change the database: its return value is ignored, and what it writes is derived from the database as built.

The file is sourced as for build_post_process(), into a fresh environment whose parent is the search path. The file is separate from R/post_build.R because targets rebuilds the database whenever R/post_build.R changes, and an edit to export code should not.

Examples

if (FALSE) { # \dontrun{
# In R/post_export.R
post_export <- function(database, path) {
  flattened <- traits.use::flatten_database(database)
  saveRDS(flattened, file.path(path, "database-flattened.rds"))
}

# In a release script
database <- readRDS("export/data/curr/database.rds")
build_post_export(database, "export/data/release")
} # }