Skip to contents

This helper function finds all entries containing specific characters in a field. Useful for identifying which entries need cleaning.

Usage

boilerplate_find_chars(
  db,
  field,
  chars,
  exclude_entries = NULL,
  category = NULL
)

Arguments

db

List. The database to search.

field

Character. The field to check.

chars

Character vector. Characters to search for.

exclude_entries

Character vector. Entries to exclude from results.

category

Character. Category if db is unified.

Value

A named list of entries containing the specified characters.

Examples

# \donttest{
# First create a sample database
unified_db <- list(
  measures = list(
    test1 = list(reference = "@Smith2023[p.45]"),
    test2 = list(reference = "Jones (2022)"),
    test3 = list(reference = "Brown[2021]")
  )
)

# Find all entries with @, [, or ] in references
entries_to_clean <- boilerplate_find_chars(
  db = unified_db,
  field = "reference",
  chars = c("@", "[", "]"),
  category = "measures"
)
#>  Found 2 entries containing specified characters

# Find entries but exclude specific ones
entries_to_clean <- boilerplate_find_chars(
  db = unified_db,
  field = "reference",
  chars = c("@", "[", "]"),
  exclude_entries = c("forgiveness", "special_*"),
  category = "measures"
)
#>  Found 2 entries containing specified characters
# }