Skip to contents

This function takes a dataframe and a configuration dictionary of origin variables, checks if specified variables are present, renames them, validates their types, and returns the modified dataframe and a list of missing variable IDs.

Usage

handle_variable_names(df, origin_variables)

Arguments

df

A dataframe containing data to be processed.

origin_variables

A list of variable mappings from the configuration file with fields `variable_id`, `variable_name`, and `variable_type`.

Value

A list containing:

dataframe

The modified dataframe with renamed variables.

missing_vars

A character vector of variable_ids that were not found in the dataframe.

Examples

# Assuming 'df' is your dataframe and 'origin_variables' is loaded from config.yml
result <- handle_variable_names(df, origin_variables)
#> Error: object 'origin_variables' not found
modified_df <- result$dataframe
#> Error: object 'result' not found
missing_vars <- result$missing_vars
#> Error: object 'result' not found