Skip to contents

This function allows editing multiple fields across multiple entries in a single operation.

Usage

boilerplate_batch_edit_multi(
  db,
  edits,
  category = NULL,
  preview = FALSE,
  confirm = TRUE,
  quiet = FALSE
)

Arguments

db

List. The database to edit.

edits

List of lists. Each sub-list should contain:

  • field: The field to edit

  • new_value: The new value

  • target_entries: Which entries to edit (optional)

  • match_pattern: Pattern to match (optional)

  • match_values: Values to match (optional)

category

Character. Category to edit if db is unified.

preview

Logical. If TRUE, shows what would be changed.

confirm

Logical. If TRUE, asks for confirmation.

quiet

Logical. If TRUE, suppresses messages.

Value

List. The modified database with the batch edits applied.

Examples

# \donttest{
# First create a sample database
unified_db <- list(
  measures = list(
    ban_hate_speech = list(reference = "old_ref", waves = "1-10"),
    born_nz = list(reference = "old_ref", waves = "1-10")
  )
)

# Update multiple fields for specific entries
unified_db <- boilerplate_batch_edit_multi(
  db = unified_db,
  edits = list(
    list(
      field = "reference",
      new_value = "sibley2021",
      target_entries = c("ban_hate_speech", "born_nz")
    ),
    list(
      field = "waves",
      new_value = "1-15",
      target_entries = c("ban_hate_speech", "born_nz")
    )
  ),
  category = "measures"
)
#> 
#> ── Edit 1 of 2: reference 
#>  Scanning database for entries to edit...
#> 
#> ── Changes made: ──
#> 
#>  ban_hate_speech: "old_ref" -> "sibley2021"
#>  born_nz: "old_ref" -> "sibley2021"
#>  Updated 2 entries
#>  Batch edit completed successfully
#> 
#> ── Edit 2 of 2: waves 
#>  Scanning database for entries to edit...
#> 
#> ── Changes made: ──
#> 
#>  ban_hate_speech: "1-10" -> "1-15"
#>  born_nz: "1-10" -> "1-15"
#>  Updated 2 entries
#>  Batch edit completed successfully
#>  All batch edits completed
# }