Skip to contents

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

Value

A list representing the merged measure database.

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

# Create example databases
db1 <- list(
  anxiety = list(
    description = "Anxiety measure from study 1",
    items = 10
  ),
  depression = list(
    description = "Depression scale",
    items = 15
  )
)

db2 <- list(
  anxiety = list(
    description = "Anxiety measure from study 2",
    items = 12
  ),
  stress = list(
    description = "Stress scale",
    items = 8
  )
)

if (FALSE) { # \dontrun{
# Merge databases interactively
merged <- boilerplate_merge_databases(db1, db2, "Study 1", "Study 2")
} # }