The boilerplate
package provides tools for managing and
generating standardised text for methods and results sections of
scientific reports. It uses a unified database system with template
variable substitution, making it easy to maintain consistent language
across projects while allowing for customisation.
New in v1.1.0: The package now defaults to a single unified JSON database, simplifying database management and improving version control integration.
{{variable}}
placeholders for dynamic contentmethods.statistical.longitudinal
)First, create and initialise your boilerplate databases:
# Initialise unified database with default content
# Creates a single boilerplate_unified.json file
# Using a temporary directory for this example
temp_intro <- file.path(tempdir(), "intro_example")
boilerplate_init(
data_path = temp_intro,
create_dirs = TRUE,
create_empty = FALSE, # Use FALSE to get example content
confirm = FALSE,
quiet = FALSE
)
Import your databases to work with them:
Generate text with variable substitution:
# Generate methods text
methods_text <- boilerplate_generate_text(
category = "methods",
sections = c("sample.default", "statistical.default"), # Use valid paths
global_vars = list(
n_total = 5000,
exposure_var = "political_conservative",
outcome_var = "anxiety",
population = "New Zealand adults"
),
db = unified_db
)
cat(methods_text)
Create formatted descriptions of your measures:
# Add a new entry
unified_db <- boilerplate_add_entry(
db = unified_db,
path = "methods.sample.online",
value = "We recruited {{n_total}} participants through online platforms.",
category = "methods"
)
# Update existing entry
unified_db <- boilerplate_update_entry(
db = unified_db,
path = "methods.sample.default",
value = "Our sample consisted of {{n_total}} {{population}}.",
category = "methods"
)
# Save changes
boilerplate_save(unified_db, data_path = temp_intro, confirm = FALSE, quiet = TRUE)
# Update multiple references at once
unified_db <- boilerplate_batch_edit(
db = unified_db,
field = "reference",
new_value = "smith2024",
target_entries = c("anxiety", "depression", "stress"),
category = "measures"
)
# Clean text fields
unified_db <- boilerplate_batch_clean(
db = unified_db,
field = "description",
remove_chars = c("@", "[", "]"),
trim_whitespace = TRUE,
category = "measures"
)
The template system uses {{variable}}
placeholders that
are replaced with actual values:
# Create a template
template_text <- "We analysed data from {{n_total}} {{population}}
({{n_female}} female, {{n_male}} male) with a mean age of {{age_mean}}
years (SD = {{age_sd}})."
# Use in your database
unified_db <- boilerplate_add_entry(
db = unified_db,
path = "methods.participants.demographics",
value = template_text,
category = "methods"
)
# Generate with variables
demographics_text <- boilerplate_generate_text(
category = "methods",
sections = "participants.demographics",
global_vars = list(
n_total = 1000,
population = "university students",
n_female = 600,
n_male = 400,
age_mean = 21.3,
age_sd = 3.2
),
db = unified_db
)
Use Version Control: Export your databases regularly for version control
Organise Hierarchically: Use dot notation for clear organisation
Document Your Variables: Keep a record of template variables
Use Meaningful Names: Choose clear, descriptive names for entries
# Work with multiple projects
# Create a project for shared content
boilerplate_init(project = "shared", confirm = FALSE)
# Copy content between projects
boilerplate_copy_from_project(
from_project = "shared",
to_project = "default",
paths = c("methods.statistical", "measures.anxiety"),
confirm = FALSE
)
# List available projects
projects <- boilerplate_list_projects(details = TRUE)
The boilerplate package includes version management features to help you track and restore different versions of your databases.
# View latest backup without restoring
backup_db <- boilerplate_restore_backup(category = "methods")
# Restore backup as current version
boilerplate_restore_backup(
category = "methods",
restore = TRUE,
confirm = TRUE
)
# Restore specific backup by timestamp
boilerplate_restore_backup(
category = "methods",
backup_version = "20240110_120000",
restore = TRUE
)
For more information and examples, see:
help(package = "boilerplate")
?boilerplate_generate_text
system.file("examples", package = "boilerplate")
system.file("extdata", package = "boilerplate")