stopifnot_all_linter: Block usage of all() within stopifnot()

stopifnot_all_linterR Documentation

Block usage of all() within stopifnot()

Description

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

Tags

best_practices, readability

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

lint(
  text = "stopifnot(y > 3, all(x < 0))",
  linters = stopifnot_all_linter()
)

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


r-lib/lintr documentation built on Dec. 20, 2024, 7:24 p.m.