Skip to contents

stopifnot(A) actually checks all(A) "under the hood" if A is a vector, and produces a better error message than stopifnot(all(A)) does.

Usage

stopifnot_all_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "stopifnot(all(x > 0))",
  linters = stopifnot_all_linter()
)
#> ::warning file=<text>,line=1,col=11::file=<text>,line=1,col=11,[stopifnot_all_linter] Use stopifnot(x) instead of stopifnot(all(x)). stopifnot(x) runs all() 'under the hood' and provides a better error message in case of failure.

lint(
  text = "stopifnot(y > 3, all(x < 0))",
  linters = stopifnot_all_linter()
)
#> ::warning file=<text>,line=1,col=18::file=<text>,line=1,col=18,[stopifnot_all_linter] Use stopifnot(x) instead of stopifnot(all(x)). stopifnot(x) runs all() 'under the hood' and provides a better error message in case of failure.

# okay
lint(
  text = "stopifnot(is.null(x) || all(x > 0))",
  linters = stopifnot_all_linter()
)

lint(
  text = "assert_that(all(x > 0))",
  linters = stopifnot_all_linter()
)