Skip to contents

length(levels(x)) is the same as nlevels(x), but harder to read.

Usage

length_levels_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "length(levels(x))",
  linters = length_levels_linter()
)
#> <text>:1:1: warning: [length_levels_linter] nlevels(x) is better than length(levels(x)).
#> length(levels(x))
#> ^~~~~~~~~~~~~~~~~

# okay
lint(
  text = "length(c(levels(x), levels(y)))",
  linters = length_levels_linter()
)
#>  No lints found.