length_levels_linter: Require usage of nlevels over length(levels(.))

length_levels_linterR Documentation

Require usage of nlevels over length(levels(.))

Description

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

Usage

length_levels_linter()

Tags

best_practices, consistency, readability

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

# okay
lint(
  text = "length(c(levels(x), levels(y)))",
  linters = length_levels_linter()
)


r-lib/lintr documentation built on Dec. 20, 2024, 7:24 p.m.