Skip to contents

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

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()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y).

lint(
  text = "sum(grepl(pattern, x)) == 0",
  linters = boolean_arithmetic_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y).

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

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