boolean_arithmetic_linter: Require usage of boolean operators over equivalent arithmetic

View source: R/boolean_arithmetic_linter.R

boolean_arithmetic_linterR Documentation

Require usage of boolean operators over equivalent arithmetic

Description

length(which(x == y)) == 0 is the same as !any(x == y), but the latter is more readable and more efficient.

Usage

boolean_arithmetic_linter()

Tags

best_practices, efficiency, readability

See Also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "length(which(x == y)) == 0L",
  linters = boolean_arithmetic_linter()
)

lint(
  text = "sum(grepl(pattern, x)) == 0",
  linters = boolean_arithmetic_linter()
)

# okay
lint(
  text = "!any(x == y)",
  linters = boolean_arithmetic_linter()
)

lint(
  text = "!any(grepl(pattern, x))",
  linters = boolean_arithmetic_linter()
)


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