Skip to contents

This function merges two unified databases, allowing the user to resolve conflicts when the same entry exists in both databases with different content. It supports both flat and hierarchical database structures across all categories.

Usage

boilerplate_merge_unified(
  db1,
  db2,
  categories = NULL,
  db1_name = "Database 1",
  db2_name = "Database 2",
  recursive = TRUE,
  sort_results = TRUE,
  quiet = FALSE
)

Arguments

db1

A list representing the first unified database.

db2

A list representing the second unified database.

categories

Character vector. Categories to merge (e.g., "measures", "methods"). If NULL (default), merges all common categories.

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).

quiet

Logical. If TRUE, suppresses all CLI alerts. Default is FALSE.

Value

A list representing the merged unified database.

Details

The function iterates through all entries in the specified categories of both databases. When an entry 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.

Entries 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{
# Import two unified databases from different locations
db1 <- boilerplate_import()
db2 <- boilerplate_import(data_path = "path/to/other/project/data")

# Merge all common categories with custom names
merged_db <- boilerplate_merge_unified(db1, db2,
                                      db1_name = "Project A",
                                      db2_name = "Project B")

# Merge only specific categories
merged_db <- boilerplate_merge_unified(db1, db2,
                                      categories = c("measures", "methods"))

# Save the merged database
boilerplate_save(merged_db)
} # }