Skip to contents

This utility function updates the data set so variable names match those listed in the data dictionary.

Usage

name_correct(DD.dict, DS.data)

Arguments

DD.dict

Data dictionary.

DS.data

Data set.

Value

Updated data set with variables renamed to match the data dictionary.

Details

Recommend use with caution; perform name_check first.

Examples

data(ExampleM)
name_check(DD.dict.M, DS.data.M)
#> $Message
#> [1] "ERROR: the variable names DO NOT match between the data dictionary and the data. If the intention behind the variable names is correct, consider using the name_correct function to automatically rename variables to match."
#> 
#> $Information
#> # A tibble: 2 × 2
#>   Data                Dict                 
#>   <chr>               <chr>                
#> 1 Data: SMOKING_HX    Dict: SMOKING_HISTORY
#> 2 Data: HX_DEPRESSION Dict: DEPRESSION_HX  
#> 
DS.data_updated <- name_correct(DD.dict.M, DS.data.M)
#> $Message
#> [1] "CORRECTED ERROR: the variable names differ between the data dictionary and the data. **ALERT** Renaming variable(s) to match those listed in the data dictionary."
#> 
#> $Information
#> # A tibble: 2 × 3
#>   Data                              Dict                             New.Data   
#>   <chr>                             <chr>                            <chr>      
#> 1 Original data name: SMOKING_HX    Dictionary name: SMOKING_HISTORY New data n…
#> 2 Original data name: HX_DEPRESSION Dictionary name: DEPRESSION_HX   New data n…
#> 
name_check(DD.dict.M, DS.data_updated)
#> $Message
#> [1] "Passed: the variable names match between the data dictionary and the data."
#> 
#> $Information
#> [1] "Variable names matched"
#>