# Create a temporary directory and initialise database
temp_dir <- tempdir()
data_path <- file.path(temp_dir, "boilerplate_batch_edit_example", "data")
# Initialise database with default content
boilerplate_init(
categories = "measures",
data_path = data_path,
create_dirs = TRUE,
create_empty = FALSE,
confirm = FALSE,
quiet = TRUE
)
# Load database
unified_db <- boilerplate_import(data_path = data_path, quiet = TRUE)
# Example 1: Change specific references
unified_db <- boilerplate_batch_edit(
db = unified_db,
field = "reference",
new_value = "example2024",
target_entries = c("anxiety", "depression"),
category = "measures",
confirm = FALSE,
quiet = TRUE
)
# Check the changes
unified_db$measures$anxiety$reference
# Example 2: Preview changes before applying
boilerplate_batch_edit(
db = unified_db,
field = "waves",
new_value = "1-5",
target_entries = "anxiety*", # All entries starting with "anxiety"
category = "measures",
preview = TRUE,
quiet = TRUE
)
# Example 3: Load database directly from file
# \donttest{
# First save the database to a JSON file
json_file <- file.path(temp_dir, "boilerplate_unified.json")
boilerplate_save(unified_db, format = "json", data_path = temp_dir, quiet = TRUE)
# Now edit directly from the file
db <- boilerplate_batch_edit(
db = json_file, # File path instead of database object
field = "description",
new_value = "Updated description",
target_entries = "anxiety",
category = "measures",
confirm = FALSE,
quiet = TRUE
)
# }
# Clean up
unlink(file.path(temp_dir, "boilerplate_batch_edit_example"), recursive = TRUE)
Run the code above in your browser using DataLab