control_names() controls the names of an object using a thesaurus.
It extracts the names of x, passes them to control(), and reassigns
the result to names(x).
control_names_ci() and control_names_fuzzy() are convenience aliases
for case insensitive and full fuzzy matching respectively.
Arguments
- x
Object with names to control.
- thesaurus
Data frame with a vector of preferred terms and a vector of variants.
- thesaurus_cols
Vector of two column names or positions specifying which columns in
thesauruscontain the preferred terms and variants respectively. Defaults to the first two columns.- ...
Other arguments passed to
control(). This includes fuzzy matching options (case_insensitive,fuzzy_boundary,fuzzy_encoding) and output options (quiet,warn_unmatched).
Examples
df <- data.frame(temp = 20, humid = 65, `wind speed` = 10, date = "2024-01-01")
thesaurus <- data.frame(
preferred = c("temperature", "humidity", "wind_speed"),
variant = c("temp", "humid", "wind speed")
)
control_names(df, thesaurus)
#> Replaced values:
#> ℹ temp → temperature
#> ℹ humid → humidity
#> Warning: Some values of `x` were not matched in `thesaurus`:
#> ✖ wind.speed
#> ✖ date
#> temperature humidity wind.speed date
#> 1 20 65 10 2024-01-01