Open lionel- opened 5 years ago
Maybe allow either a pair of new and old arguments or a single new data frame?
Also related to #15
This will also resolve https://github.com/tidyverse/dplyr/issues/4628, since we eliminate the round trip to symbols.
We'll need to come up with a new name for the function so we can deprecate dplyr::recode()
Alternatively it might be possible to implement the new functionality in recode()
, and deprecate the current functionality when we detect named inputs.
Following https://github.com/lionel-/recode/blob/master/R/recode.R
Specify the mapping of values with a tibble of
.new
and.old
columns (here created withkeys()
, not sure about this helper). Thenew
column of keys acts as a generalisation of names which preserves the types. Missing values can be encoded in the spec:Basic usage:
You can recode multiple values to a same key by supplying a list column in
.old
:You can recode vectors to a tibble:
And you can recode tibbles to vectors:
In a data cleaning scripts, all specs can be neatly kept at the top of the file, then we use
mutate()
and mapping variants to recode variables one by one or in bulk.