@@ -62,6 +62,32 @@ values that could not be matched in the thesaurus. These can be
6262suppressed with ` quiet = TRUE ` and ` warn_unmatched = FALSE `
6363respectively.
6464
65+ Use
66+ [ ` control_names() ` ] ( https://controller.joeroe.io/reference/control_names.md )
67+ to control the names of an object rather than its values. This is useful
68+ for standardising column names in data frames:
69+
70+ ``` r
71+
72+ df <- data.frame (temp = 20 , humid = 65 , `wind speed` = 10 , date = " 2024-01-01" )
73+ df
74+ # > temp humid wind.speed date
75+ # > 1 20 65 10 2024-01-01
76+
77+ control_names(df , thesaurus = data.frame (
78+ preferred = c(" temperature" , " humidity" , " wind_speed" ),
79+ variant = c(" temp" , " humid" , " wind speed" )
80+ ))
81+ # > Replaced values:
82+ # > ℹ temp → temperature
83+ # > ℹ humid → humidity
84+ # > Warning: Some values of `x` were not matched in `thesaurus`:
85+ # > ✖ wind.speed
86+ # > ✖ date
87+ # > temperature humidity wind.speed date
88+ # > 1 20 65 10 2024-01-01
89+ ```
90+
6591## Fuzzy matching
6692
6793[ ` control() ` ] ( https://controller.joeroe.io/reference/control.md ) also
@@ -113,29 +139,21 @@ control("foo", df, fuzzy_encoding = TRUE, quiet = FALSE)
113139# > [1] "bar"
114140```
115141
116- To inspect which type of match was used for each value, set
117- ` coalesce = FALSE ` . This returns a data frame with a column for each
118- match type, rather than a single vector:
142+ To inspect which type of match was used for each value, use
143+ [ ` control_matches() ` ] ( https://controller.joeroe.io/reference/control_matches.md ) .
144+ It returns a data frame with a column for each match type, rather than a
145+ single vector:
119146
120147``` r
121148
122- control(shades_ci , colour_thesaurus ,
123- case_insensitive = TRUE , coalesce = FALSE )
124- # > Replaced values:
125- # > ℹ DAFFODIL → yellow
126- # > ℹ PURPLE → purple
127- # > ℹ AZURE → blue
128- # > ℹ NAVY → blue
129- # > ℹ VIOLET → purple
130- # > Warning: Some values of `x` were not matched in `thesaurus`:
131- # > ✖ MAGENTA
132- # > exact case_insensitive
133- # > 1 <NA> yellow
134- # > 2 <NA> purple
135- # > 3 <NA> <NA>
136- # > 4 <NA> blue
137- # > 5 <NA> blue
138- # > 6 <NA> purple
149+ control_matches(shades_ci , colour_thesaurus , case_insensitive = TRUE )
150+ # > term exact_match case_insensitive_match
151+ # > 1 DAFFODIL <NA> yellow
152+ # > 2 PURPLE <NA> purple
153+ # > 3 MAGENTA <NA> <NA>
154+ # > 4 AZURE <NA> blue
155+ # > 5 NAVY <NA> blue
156+ # > 6 VIOLET <NA> purple
139157```
140158
141159## Thesaurus format
0 commit comments