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. Exports are written as JSON.
Usage
boilerplate_export(
db,
output_file = NULL,
select_elements = NULL,
data_path = NULL,
format = "json",
confirm = TRUE,
create_dirs = FALSE,
quiet = FALSE,
pretty = TRUE,
save_by_category = TRUE,
project = "default"
)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 tools::R_user_dir("boilerplate", "data").
- format
Character. Format to save. "json" (default) is the supported format. "rds" and "both" are no longer supported because the package does not write new RDS databases.
- 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.
- project
Character. Project name for organizing databases. Default is "default". Projects are stored in separate subdirectories to allow multiple independent boilerplate collections.
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.json",
data_path = export_path,
confirm = FALSE,
quiet = TRUE
)
# Clean up
unlink(file.path(temp_dir, "boilerplate_export_example"), recursive = TRUE)
