Skip to contents

any(!x) is logically equivalent to !any(x); ditto for the equivalence of all(!x) and !any(x). Negating after aggregation only requires inverting one logical value, and is typically more readable.

Usage

outer_negation_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "all(!x)",
  linters = outer_negation_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[outer_negation_linter] !any(x) is better than all(!x). The former applies negation only once after aggregation instead of many times for each element of x.

lint(
  text = "any(!x)",
  linters = outer_negation_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[outer_negation_linter] !all(x) is better than any(!x). The former applies negation only once after aggregation instead of many times for each element of x.

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

lint(
  text = "!all(x)",
  linters = outer_negation_linter()
)