Skip to contents

This function is partially deprecated. For basic list operations, please use boilerplate_import(category) instead. Other functionality is maintained for backward compatibility.

This function manages text entries in a boilerplate database, allowing for adding, updating, removing, retrieving, and listing text entries. Supports hierarchical organisation through dot-separated paths.

Usage

boilerplate_manage_text(
  category = c("measures", "methods", "results", "discussion", "appendix", "template"),
  action = c("add", "update", "remove", "get", "list", "save"),
  name = NULL,
  value = NULL,
  db = NULL,
  template_vars = list(),
  text_path = NULL,
  file_name = NULL,
  warn_missing = TRUE,
  create_dirs = FALSE,
  confirm = TRUE,
  dry_run = FALSE,
  quiet = FALSE
)

boilerplate_manage_text(
  category = c("measures", "methods", "results", "discussion", "appendix", "template"),
  action = c("add", "update", "remove", "get", "list", "save"),
  name = NULL,
  value = NULL,
  db = NULL,
  template_vars = list(),
  text_path = NULL,
  file_name = NULL,
  warn_missing = TRUE,
  create_dirs = FALSE,
  confirm = TRUE,
  dry_run = FALSE,
  quiet = FALSE
)

Arguments

category

Character. Category of text (e.g., "methods", "results").

action

Character. Action to perform: "add", "update", "remove", "get", "list", or "save".

name

Character. Name/path of the text entry. Can use dot notation for nesting (e.g., "statistical.longitudinal.lmtp").

value

Character. Text content to add or update.

db

List. Optional database to use (required for "save", optional for other actions).

template_vars

List. Variables to substitute in template when getting text.

text_path

Character. Path to the directory where text database files are stored. If NULL (default), the function will look in the following locations in order:

  1. "boilerplate/data/" subdirectory of the current working directory (via here::here())

  2. Package installation directory's "boilerplate/data/" folder

  3. "boilerplate/data/" relative to the current working directory

file_name

Character. Name of the file to save or load (without path). If NULL (default), uses "category_db.rds". Note: For "save" action, file_name must be explicitly provided.

warn_missing

Logical. Whether to warn about missing template variables.

create_dirs

Logical. If TRUE, creates directories that don't exist. Default is FALSE.

confirm

Logical. If TRUE, asks for confirmation before creating directories or modifying files. Default is TRUE.

dry_run

Logical. If TRUE, simulates the operation without writing files. Default is FALSE.

quiet

Logical. If TRUE, suppresses all CLI alerts. Default is FALSE.

Value

Depends on the action (see original function documentation).

Depending on the action:

  • "add", "update", "remove": The modified database (list).

  • "get": The text with template variables substituted (character).

  • "list": The entire database (list).

  • "save": Invisible NULL (called for side effects).

Examples

if (FALSE) { # \dontrun{
# List existing text entries
methods_db <- boilerplate_manage_text(
  category = "methods",
  action = "list"
)

# Add a new text entry with dot notation for nesting
methods_db <- boilerplate_manage_text(
  category = "methods",
  action = "add",
  name = "statistical.longitudinal.lmtp",
  value = "We used the LMTP estimator with {{algorithm}} as the base learner."
)

# Add a document template
template_db <- boilerplate_manage_text(
  category = "template",
  action = "add",
  name = "conference_abstract",
  value = "# {{title}}\n\n**Authors**: {{authors}}\n\n## Background\n{{background}}\n\n## Methods\n{{methods}}\n\n## Results\n{{results}}"
)

# Retrieve text with template variables substituted
lmtp_text <- boilerplate_manage_text(
  category = "methods",
  action = "get",
  name = "statistical.longitudinal.lmtp",
  template_vars = list(algorithm = "Super Learner")
)

# Save changes to database with explicit file_name to prevent accidental overwrites
boilerplate_manage_text(
  category = "methods",
  action = "save",
  db = methods_db,
  file_name = "my_methods_db.rds"
)

# Remove an entry
methods_db <- boilerplate_manage_text(
  category = "methods",
  action = "remove",
  name = "statistical.longitudinal.lmtp"
)
} # }