Skip to content

fct_inorder() fails if factor contains empty levels #262

Description

@jwilliman

Running forcats::fct_inorder on factors with empty levels produces an (informative) error.

Is this behaviour expected/desired, or should empty levels be automatically dropped (with a warning)? If expected, would be good to flag on the help file.

library(forcats)
f <- factor(rev(letters[1:5]), levels = letters[1:6])
fct_inorder(f)
#> Error: `idx` must contain one integer for each level of `f`
fct_infreq(f)
#> [1] e d c b a
#> Levels: a b c d e f
fct_inorder(fct_drop(f))
#> [1] e d c b a
#> Levels: e d c b a

Created on 2020-04-29 by the reprex package (v0.3.0)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions