Skip to content

fct_expand() needs after argument #138

@billdenney

Description

@billdenney

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions