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()
)
#> <text>:1:11: warning: [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.
#> stopifnot(all(x > 0))
#>           ^~~~~~~~~~

lint(
  text = "stopifnot(y > 3, all(x < 0))",
  linters = stopifnot_all_linter()
)
#> <text>:1:18: warning: [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.
#> stopifnot(y > 3, all(x < 0))
#>                  ^~~~~~~~~~

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

lint(
  text = "assert_that(all(x > 0))",
  linters = stopifnot_all_linter()
)
#>  No lints found.