Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fct_lump_n loses interlacer class #8

Open
khusmann opened this issue Aug 9, 2024 · 1 comment
Open

fct_lump_n loses interlacer class #8

khusmann opened this issue Aug 9, 2024 · 1 comment

Comments

@khusmann
Copy link
Owner

khusmann commented Aug 9, 2024

library(interlacer)
library(forcats)

foo <- interlaced(c("a", "a", "b", "b", "c", "OMITTED"), na = "OMITTED") |>
  map_value_channel(as.factor)

fct_lump_n(foo, 2, other_level = "OTHER")
#> [1] a     a     b     b     OTHER <NA> 
#> attr(,"na_channel_values")
#> [1] <NA>    <NA>    <NA>    <NA>    <NA>    OMITTED
#> Levels: OMITTED
#> Levels: a b OTHER

Created on 2024-08-08 with reprex v2.0.2

@khusmann
Copy link
Owner Author

khusmann commented Aug 9, 2024

Ah, it's from fct_lump_n -> lvls_other() -> fct_relevel() -> lvls_reorder() -> refactor(). refactor() overwrites the class attribute

So refactor() is written to preserve all the extended attributes of the original factor, but not extensions of the class? It seems like it'd be better if it also preserved the subclass of the factor as well...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant