The boilerplate package is designed to streamline
scientific writing in Quarto documents. This vignette demonstrates a
complete workflow for using boilerplate to manage reusable
text templates in your research papers.
Quarto is becoming the standard for reproducible scientific
documents. The boilerplate package enhances Quarto
workflows by:
vignette("boilerplate-json-workflow"))my-research-project/
├── .boilerplate-data/          # boilerplate databases
├── manuscript/
│   ├── paper.qmd               # Main manuscript
│   ├── _methods.qmd            # Methods section
│   └── references.bib          # Bibliography (auto-copied)
└── .gitignore                  # Exclude backupsAdd to your .gitignore:
# Exclude boilerplate backups
.boilerplate-data/*.bakCreate reusable methods templates with placeholders:
# Import database first
db <- boilerplate_import(data_path = data_path, quiet = TRUE)
# Add participant recruitment template to the unified database
db <- boilerplate_add_entry(
  db,
  path = "methods.participants.recruitment",
  value = "We recruited {{n_participants}} participants through {{recruitment_method}}.",
  category = "methods"
)
# Save the updated database
boilerplate_save(db, data_path = data_path, confirm = FALSE, quiet = TRUE)Store information about your measures:
# Add a measure to the unified database
db$measures$gad7 <- list(
  name = "GAD-7",
  description = "Generalized Anxiety Disorder 7-item scale",
  type = "ordinal",  # Required field
  items = list(
    "Feeling nervous, anxious, or on edge",
    "Not being able to stop or control worrying"
  ),
  reference = "@spitzer2006"
)
# Save the updated database
boilerplate_save(db, data_path = data_path, confirm = FALSE, quiet = TRUE)Here’s how to use boilerplate in your Quarto document:
# Import database (using the temp path from above)
db <- boilerplate_import(data_path = data_path, quiet = TRUE)
# Generate methods text
methods_text <- boilerplate_generate_text(
  category = "methods",
  sections = "participants.recruitment",
  global_vars = list(
    n_participants = 250,
    recruitment_method = "online panels"
  ),
  db = db,
  quiet = TRUE
)
# Output: "We recruited 250 participants through online panels."Your main Quarto document (paper.qmd) might look
like:
Then in the document:
## Introduction
[Your introduction...]
## Methods
{{< include _methods.qmd >}}
## Results
[Your results...]And in _methods.qmd:
library(boilerplate)
# Load database and generate text
db <- boilerplate_import(data_path = data_path, quiet = TRUE)
# Generate participant section
participant_text <- boilerplate_generate_text(
  category = "methods",
  sections = "participants.recruitment",
  global_vars = list(n_participants = 250),
  db = db
)
cat(participant_text).boilerplate-data/*.rds files to gitmethods.participants.recruitment)The boilerplate package can manage your bibliography file, ensuring consistent citations across projects:
# Add bibliography information to your database
db <- boilerplate_import(data_path = data_path, quiet = TRUE)
# Using the example bibliography included with the package
example_bib <- system.file("extdata", "example_references.bib", package = "boilerplate")
db <- boilerplate_add_bibliography(
  db,
  url = paste0("file://", example_bib),
  local_path = "references.bib"
)
# Save the updated database
boilerplate_save(db, data_path = data_path, confirm = FALSE, quiet = TRUE)When generating text, automatically copy the bibliography:
# Generate text and copy bibliography
methods_text <- boilerplate_generate_text(
  category = "methods",
  sections = "statistical.default",  # Use existing section
  db = db,
  copy_bibliography = TRUE,
  bibliography_path = "manuscript/"  # Copy to manuscript directory
)Your Quarto document header would include:
Update multiple entries at once:
Use Quarto parameters with boilerplate:
Then in your code:
The boilerplate package enhances Quarto workflows by
providing a robust system for managing reusable text templates. This
approach ensures consistency, reduces errors, and streamlines the
scientific writing process.