Require usage of nlevels over length(levels(.))
Source:R/length_levels_linter.R
length_levels_linter.Rd
length(levels(x))
is the same as nlevels(x)
, but harder to read.
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.