tidyverse / forcats

🐈🐈🐈🐈: tools for working with categorical variables (factors)
https://forcats.tidyverse.org/
Other
553 stars 126 forks source link

```fct_reorder``` treatment of missing values in .x depends on whether .f is a factor or a character vector #359

Open dominikbach opened 10 months ago

dominikbach commented 10 months ago

When .x contains missing values, this throws an error if .f is a character vector but not if .f is a factor (with no missing values in either case).

This behaviour is not documented (and I suspect is not intended). It occurs in v0.5.0 and v1.0.0.

Example:

.f <- c("a", "b", "c")
.x <- c(1, 2, NA)
forcats::fct_reorder(.f, .x)
forcats::fct_reorder(forcats::as_factor(.f), .x)