This function exports a boilerplate database or selected elements to disk. It supports exporting entire databases, specific categories, or selected elements using dot notation paths. Can export in RDS, JSON, or both formats.
Usage
boilerplate_export(
db,
output_file = NULL,
select_elements = NULL,
data_path = NULL,
format = "rds",
confirm = TRUE,
create_dirs = FALSE,
quiet = FALSE,
pretty = TRUE,
save_by_category = TRUE
)
Arguments
- db
List. The database to export (unified or single category).
- output_file
Character. Optional output filename. If NULL, uses default naming.
- select_elements
Character vector. Optional paths to export (supports wildcards).
- data_path
Character. Base path for data directory. If NULL (default), uses here::here("boilerplate", "data").
- format
Character. Format to save: "rds" (default), "json", or "both".
- confirm
Logical. If TRUE (default), asks for confirmation before overwriting.
- create_dirs
Logical. If TRUE, creates directories if they don't exist.
- quiet
Logical. If TRUE, suppresses all CLI alerts. Default is FALSE.
- pretty
Logical. If TRUE (default), pretty-print JSON for readability.
- save_by_category
Logical. If TRUE (default), saves unified databases by category.
Examples
# Create a temporary directory and initialise databases
temp_dir <- tempdir()
data_path <- file.path(temp_dir, "boilerplate_export_example", "data")
# Initialise and import databases
boilerplate_init(
categories = c("methods", "measures"),
data_path = data_path,
create_dirs = TRUE,
confirm = FALSE,
quiet = TRUE
)
unified_db <- boilerplate_import(data_path = data_path, quiet = TRUE)
# Export entire database
export_path <- file.path(temp_dir, "export")
boilerplate_export(
db = unified_db,
data_path = export_path,
create_dirs = TRUE,
confirm = FALSE,
quiet = TRUE
)
# Export selected elements
boilerplate_export(
db = unified_db,
select_elements = "methods.*",
output_file = "methods_only.rds",
data_path = export_path,
confirm = FALSE,
quiet = TRUE
)
# Clean up
unlink(file.path(temp_dir, "boilerplate_export_example"), recursive = TRUE)