This function merges two measure databases, allowing the user to resolve conflicts when the same measure exists in both databases with different content. It supports both flat and hierarchical database structures.
Usage
boilerplate_merge_databases(
db1,
db2,
db1_name = "Database 1",
db2_name = "Database 2",
recursive = TRUE,
sort_results = TRUE
)
Arguments
- db1
A list representing the first measure database.
- db2
A list representing the second measure database.
- db1_name
Character string. The name of the first database (default: "Database 1").
- db2_name
Character string. The name of the second database (default: "Database 2").
- recursive
Logical. Whether to merge hierarchical structures recursively (default: TRUE).
- sort_results
Logical. Whether to sort the merged database alphabetically (default: TRUE).
Details
The function iterates through all measures in both databases. When a measure exists in both databases:
If the entries are identical, it keeps one copy.
If the entries differ, it prompts the user to choose which entry to keep.
Measures that exist in only one database are automatically added to the merged database. If recursive is TRUE, the function will recursively merge nested folders/categories. If sort_results is TRUE, the function will sort the merged database alphabetically at each level.
Examples
if (FALSE) { # \dontrun{
# Merge two flat databases with default names
merged_db <- boilerplate_merge_databases(test_a, test_b)
# Merge two hierarchical databases with custom names
merged_db <- boilerplate_merge_databases(test_a, test_b, "NZAVS 2009", "NZAVS 2020")
# Merge but do not process nested structures recursively
merged_db <- boilerplate_merge_databases(test_a, test_b, recursive = FALSE)
# Merge but do not sort the result
merged_db <- boilerplate_merge_databases(test_a, test_b, sort_results = FALSE)
} # }