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_expand() needs after argument #138

Closed
billdenney opened this issue Jul 17, 2018 · 3 comments · Fixed by #332
Closed

fct_expand() needs after argument #138

billdenney opened this issue Jul 17, 2018 · 3 comments · Fixed by #332
Labels
feature a feature request or enhancement
Milestone

Comments

@billdenney
Copy link
Contributor

For fct_expand, it would be useful to be able to insert the new level somewhere other than as the last level in the levels. This is especially true for ordered factors.

Something like the following is what I'm thinking:

fct_expand <- function(f, ..., after=NULL) {
  f <- forcats:::check_factor(f)
  
  new_levels <- rlang::chr(...)
  if (is.null(after)) {
    all_levels <- union(levels(f), new_levels)
  } else {
    all_levels <-
      append(setdiff(levels(f), new_levels),
             new_levels,
             after=after)
  }
  lvls_expand(f, new_levels=all_levels)
}
@hadley hadley added the feature a feature request or enhancement label Jan 4, 2019
@hadley
Copy link
Member

hadley commented Jan 4, 2019

Before this can be implemented we need to review the interface to make sure it's consistent with other tidyverse functions.

@hadley hadley added this to the v1.0.0 milestone Jan 3, 2023
@hadley hadley changed the title Feature Request: Add an "after" argument to fct_expand fct_expand() needs after Jan 3, 2023
@hadley hadley changed the title fct_expand() needs after fct_expand() needs after argument Jan 3, 2023
@hadley
Copy link
Member

hadley commented Jan 3, 2023

Seems reasonable to use after to match fct_relevel().

hadley added a commit that referenced this issue Jan 3, 2023
hadley added a commit that referenced this issue Jan 4, 2023
@billdenney
Copy link
Contributor Author

Thanks!

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

Successfully merging a pull request may close this issue.

2 participants