This utility function reorders the data dictionary to match the data set.
Examples
data(ExampleN)
name_check(DD.dict.N, DS.data.N)
#> $Message
#> [1] "ERROR: the variable names match between the data dictionary and the data, but they are in the wrong order. Consider using reorder_dictionary function to automatically reorder the dictionary so that you can continue working through the checks."
#>
#> $Information
#> # A tibble: 10 × 2
#> Data Dict
#> <chr> <chr>
#> 1 Data: ABD_CIRC Dict: HIP_CIRC
#> 2 Data: HIP_CIRC Dict: ABD_SKF
#> 3 Data: ABD_SKF Dict: SUP_SKF
#> 4 Data: SUP_SKF Dict: ABD_CIRC
#> 5 Data: BP_DIASTOLIC Dict: HTN
#> 6 Data: HTN Dict: SMOKING_HX
#> 7 Data: SMOKING_HX Dict: LENGTH_SMOKING_YEARS
#> 8 Data: LENGTH_SMOKING_YEARS Dict: HEART_RATE
#> 9 Data: HEART_RATE Dict: PHYSICAL_ACTIVITY
#> 10 Data: PHYSICAL_ACTIVITY Dict: BP_DIASTOLIC
#>
DD.dict_updated <- reorder_dictionary(DD.dict.N, DS.data.N)
#> $Message
#> [1] "CORRECTED ERROR: the variable names match between the data dictionary and the data, but they were in the wrong order. ***ALERT**** this function has temporarily reordered the dictionary to match the data so that you can continue working through the checks."
#>
#> $Information
#> # A tibble: 10 × 3
#> Data Dict New.Dict
#> <chr> <chr> <chr>
#> 1 Data: ABD_CIRC Dict: HIP_CIRC Data: ABD_CIRC
#> 2 Data: HIP_CIRC Dict: ABD_SKF Data: HIP_CIRC
#> 3 Data: ABD_SKF Dict: SUP_SKF Data: ABD_SKF
#> 4 Data: SUP_SKF Dict: ABD_CIRC Data: SUP_SKF
#> 5 Data: BP_DIASTOLIC Dict: HTN Data: BP_DIASTOLIC
#> 6 Data: HTN Dict: SMOKING_HX Data: HTN
#> 7 Data: SMOKING_HX Dict: LENGTH_SMOKING_YEARS Data: SMOKING_HX
#> 8 Data: LENGTH_SMOKING_YEARS Dict: HEART_RATE Data: LENGTH_SMOKING_Y…
#> 9 Data: HEART_RATE Dict: PHYSICAL_ACTIVITY Data: HEART_RATE
#> 10 Data: PHYSICAL_ACTIVITY Dict: BP_DIASTOLIC Data: PHYSICAL_ACTIVITY
#>
name_check(DD.dict_updated, DS.data.N)
#> $Message
#> [1] "Passed: the variable names match between the data dictionary and the data."
#>
#> $Information
#> [1] "Variable names matched"
#>