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"
)path, invisibly
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.
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")
} # }