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()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[length_levels_linter] nlevels(x) is better than length(levels(x)).
# okay
lint(
text = "length(c(levels(x), levels(y)))",
linters = length_levels_linter()
)