Skip to contents

This function allows batch editing of specific fields across multiple entries in a boilerplate database. It supports pattern matching, explicit lists, and various editing operations.

Usage

boilerplate_batch_edit(
  db,
  field,
  new_value,
  target_entries = NULL,
  match_pattern = NULL,
  match_values = NULL,
  category = NULL,
  recursive = TRUE,
  case_sensitive = FALSE,
  preview = FALSE,
  confirm = TRUE,
  quiet = FALSE
)

Arguments

db

List. The database to edit (can be a single category or unified database).

field

Character. The field to edit (e.g., "reference", "description").

new_value

Character. The new value to set for the field.

target_entries

Character vector. Entries to edit. Can be:

  • Specific entry names (e.g., c("ban_hate_speech", "born_nz"))

  • Patterns with wildcards (e.g., "anxiety*" matches all entries starting with "anxiety")

  • "all" to edit all entries

  • NULL to use pattern/value matching

match_pattern

Character. Pattern to match in the current field values. Only entries with matching values will be updated. Ignored if target_entries is specified.

match_values

Character vector. Specific values to match. Only entries with these exact values will be updated. Ignored if target_entries is specified.

category

Character. If db is unified, specifies which category to edit (e.g., "measures", "methods"). If NULL, attempts to detect.

recursive

Logical. Whether to search recursively through nested structures.

case_sensitive

Logical. Whether pattern matching is case sensitive.

preview

Logical. If TRUE, shows what would be changed without making changes.

confirm

Logical. If TRUE, asks for confirmation before making changes.

quiet

Logical. If TRUE, suppresses non-essential messages.

Value

The modified database (invisibly if preview=TRUE).

Examples

if (FALSE) { # \dontrun{
# Load database
unified_db <- boilerplate_import()

# Example 1: Change specific references to "sibley2021"
unified_db <- boilerplate_batch_edit(
  db = unified_db,
  field = "reference",
  new_value = "sibley2021",
  target_entries = c("ban_hate_speech", "born_nz"),
  category = "measures"
)

# Example 2: Update all references containing "NZAVS"
unified_db <- boilerplate_batch_edit(
  db = unified_db,
  field = "reference",
  new_value = "sibley2021",
  match_pattern = "NZAVS",
  category = "measures"
)

# Example 3: Preview changes before applying
boilerplate_batch_edit(
  db = unified_db,
  field = "reference",
  new_value = "sibley2021",
  target_entries = c("ban_hate_speech", "born_nz"),
  category = "measures",
  preview = TRUE
)

# Example 4: Update all entries with a specific reference value
unified_db <- boilerplate_batch_edit(
  db = unified_db,
  field = "reference",
  new_value = "sibley2024",
  match_values = c("dore2022boundaries", "string_is Developed for the NZAVS."),
  category = "measures"
)

# Example 5: Batch edit waves information
unified_db <- boilerplate_batch_edit(
  db = unified_db,
  field = "waves",
  new_value = "1-15",
  target_entries = "anxiety*",  # All entries starting with "anxiety"
  category = "measures"
)
} # }