harmonize_var_names: Harmonize variable names across surveys

View source: R/harmonize_var_names.R

harmonize_var_namesR Documentation

Harmonize variable names across surveys

Description

'harmonize_var_names()' renames variables across multiple surveys to a shared harmonized naming scheme.

The harmonization rules are defined in a metadata table, typically created with [metadata_create()].

Usage

harmonize_var_names(
  survey_list,
  metadata,
  old = "var_name_orig",
  new = "var_name_suggested",
  rowids = TRUE
)

Arguments

survey_list

A list of survey objects, typically imported with [read_surveys()].

metadata

A metadata table containing harmonization rules. Typically created with [metadata_create()] and combined across surveys.

old

Name of the column in 'metadata' containing the original variable names.

new

Name of the column in 'metadata' containing the harmonized variable names.

rowids

Logical. Should original 'rowid' variables be renamed to '"uniqid"'?

Details

Harmonize variable names in a list of survey objects using a metadata crosswalk table.

The function can also be used for survey subsetting workflows. If 'metadata' contains only a subset of variables for a survey, only those variables are retained in the harmonized output.

Value

A list of surveys with harmonized variable names.

See Also

[metadata_create()], [crosswalk()]

Other harmonization functions: collect_val_labels(), crosswalk_surveys(), harmonize_na_values(), harmonize_survey_values(), harmonize_values(), is.crosswalk_table(), label_normalize()

Examples

examples_dir <- system.file(
  "examples",
  package = "retroharmonize"
)

survey_files <- dir(
  examples_dir,
  pattern = "\\.rds$"
)

example_surveys <- read_surveys(
  file.path(examples_dir, survey_files)
)

metadata <- metadata_create(
  example_surveys
)

metadata$var_name_suggested <-
  label_normalize(metadata$var_name)

metadata$var_name_suggested[
  metadata$label_orig == "age_education"
] <- "age_education"

harmonized_surveys <- harmonize_var_names(
  survey_list = example_surveys,
  metadata = metadata
)

harmonized_surveys[[1]]


retroharmonize documentation built on May 21, 2026, 9:06 a.m.