This function saves a boilerplate database to disk with entry-level change detection.
Usage
boilerplate_save(
db,
category = NULL,
data_path = NULL,
confirm = TRUE,
create_dirs = FALSE,
quiet = FALSE,
entry_level_confirm = TRUE,
create_backup = TRUE,
select_elements = NULL,
output_file = NULL
)
Arguments
- db
List. The database to save.
- category
Character. Category of the database. Options include "measures", "methods", "results", "discussion", "appendix", "template". If NULL and db is a named list matching category names, saves each category.
- data_path
Character. Base path for data directory. If NULL (default), uses here::here("boilerplate", "data").
- confirm
Logical. If TRUE, asks for confirmation before overwriting. Default is TRUE.
- create_dirs
Logical. If TRUE, creates directories that don't exist. Default is FALSE.
- quiet
Logical. If TRUE, suppresses all CLI alerts. Default is FALSE.
- entry_level_confirm
Logical. If TRUE, shows changes at the entry level and asks for confirmation. Default is TRUE.
- create_backup
Logical. If TRUE, creates a backup of existing database before saving. Default is TRUE.
- select_elements
Character vector. Paths to select in dot notation (e.g., "statistical.longitudinal.lmtp"). Use "" for wildcard selection (e.g., "statistical." selects all statistical methods). If NULL (default), saves the entire database.
- output_file
Character. Name of the output file if saving selected elements to a separate file. If NULL (default), overwrites the original file.
Value
Invisibly returns a named list with logical values indicating which categories were successfully saved, or the file path if a single category was saved.
Examples
# save a specific database
methods_db <- boilerplate_import("methods")
#> ℹ using default path: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ! data directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ℹ importing methods database
#> ! methods database file not found, using default
methods_db$new_section <- "New content"
boilerplate_save(methods_db, "methods")
#> ℹ using default path: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ✖ directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data
#> Error in boilerplate_save(methods_db, "methods"): Directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data. Set create_dirs=TRUE to create it.
# save selected elements from a database
unified_db <- boilerplate_import()
#> ℹ importing all categories
#> ℹ using default path: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ! data directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ℹ importing measures database
#> ! measures database file not found, using default
#> ℹ importing methods database
#> ! methods database file not found, using default
#> ℹ importing results database
#> ! results database file not found, using default
#> ℹ importing discussion database
#> ! discussion database file not found, using default
#> ℹ importing appendix database
#> ! appendix database file not found, using default
#> ℹ importing template database
#> ! template database file not found, using default
boilerplate_save(unified_db,
select_elements = c("methods.statistical.*", "results.main_effect"),
output_file = "selected_elements.rds")
#> ℹ using default path: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ✖ directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data
#> Error in boilerplate_save(unified_db, select_elements = c("methods.statistical.*", "results.main_effect"), output_file = "selected_elements.rds"): Directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data. Set create_dirs=TRUE to create it.
# save multiple databases at once
all_dbs <- boilerplate_import()
#> ℹ importing all categories
#> ℹ using default path: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ! data directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ℹ importing measures database
#> ! measures database file not found, using default
#> ℹ importing methods database
#> ! methods database file not found, using default
#> ℹ importing results database
#> ! results database file not found, using default
#> ℹ importing discussion database
#> ! discussion database file not found, using default
#> ℹ importing appendix database
#> ! appendix database file not found, using default
#> ℹ importing template database
#> ! template database file not found, using default
all_dbs$methods$new_section <- "New content"
boilerplate_save(all_dbs)
#> ℹ using default path: /Users/joseph/GIT/boilerplate/boilerplate/data
#> ✖ directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data
#> Error in boilerplate_save(all_dbs): Directory does not exist: /Users/joseph/GIT/boilerplate/boilerplate/data. Set create_dirs=TRUE to create it.