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

preserve subclasses as well as attrs in refactor() #367

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

khusmann
Copy link

@khusmann khusmann commented Aug 9, 2024

As @TimTaylor first pointed out in #83, refactor() overwrites the class with the reset result of factor. This affects a bunch of methods downstream of refactor() like lvls_expand(), lvls_reorder(), fct_lump_n(), etc.

Because refactor() sometimes needs to set ordered in the class list, it's not as simple as ignoring the class of the new factor. Instead, if ordered is being toggled off, it drops "ordered" from the original class list; if it's being toggled on, it adds "ordered" to the original class list; if nothing is changed it uses the original class list. As a result, all the subclasses in the original factor propagate to the result, instead of getting lost.

The tests in lvls-test.R demonstrate this functionality.

Cheers!

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

Successfully merging this pull request may close these issues.

1 participant