Fct_recode vs recode_factors

dplyr
forcats

#1

Hi,

Is there any functional differences between the function forcats::fct_recode and dplyr::recode_factor? It seems to me as if they are quite similar functionally, with the dplyr::recode_factor having the added benefit of

  1. Ability to specify .missing and .default arguments
  2. Ability to take in non-factor vectors

and forcats::fct_recode having the benefit of

  1. Ability to keep any unchanged factors the same as before

Additionally, my understanding of the functions are that their recoding arguments work in the opposite direction (i.e. forcats::fct_recode has arguments that go: new = “old”, while dplyr::recode_factor has arguments that go: old = “new”).

Are there other differences I am missing?

Thanks


#2

This is a good case of going to the source, as it seems you’ve done. I haven’t done any research on this, but I’d venture a guess that dplyr is required/imported more often than forcats, which (again, speculating) is one reason it might be used inside of a package in lieu of forcats.

dplyr::recode_factor is part of the dplyr recode family of functions. It has .default and .missing arguments last, as you pointed out, and shares its overall structure with the other recode funs in dplyr.:

The forcats::recode_factor code is easier reading (IMHO), and definitely seems to fit in the philosophy of a function that does one thing and does that one thing well. The error messages are more informative, which I’m guessing is made possible, in part, by the simpler logic of it all.