all_equal_linter: Warn about invalid usage of 'all.equal()'

View source: R/all_equal_linter.R

all_equal_linterR Documentation

Warn about invalid usage of all.equal()

Description

all.equal() returns TRUE in the absence of differences but return a character string (not FALSE) in the presence of differences. Usage of all.equal() without wrapping it in isTRUE() in if clauses, or preceded by the negation operator !, are thus likely to generate unexpected errors if the compared objects have differences. An alternative is to use identical() to compare vector of strings or when exact equality is expected.

Usage

all_equal_linter()

Tags

common_mistakes, robustness

See Also

linters for a complete list of linters available in lintr.

Examples

# lints
lint(
  text = 'if (all.equal(a, b)) message("equal")',
  linters = all_equal_linter()
)

lint(
  text = '!all.equal(a, b)',
  linters = all_equal_linter()
)

lint(
  text = 'isFALSE(all.equal(a, b))',
  linters = all_equal_linter()
)

# okay
lint(
  text = 'if (isTRUE(all.equal(a, b))) message("equal")',
  linters = all_equal_linter()
)

lint(
  text = '!identical(a, b)',
  linters = all_equal_linter()
)

lint(
  text = "!isTRUE(all.equal(a, b))",
  linters = all_equal_linter()
)


lintr documentation built on Nov. 27, 2025, 9:06 a.m.