must: Convert warnings to errors

Description Usage Arguments Value See Also Examples

View source: R/coding.R

Description

Raise an error if a warning occurs. Useful for making certain tests more strict. It is a bit easier to use than changing the ‘warn’ entry of options from the base package (because the entry would usually need to be set back).

Usage

1
  must(expr, msg = NULL, ..., domain = NULL)

Arguments

expr

R expression to evaluate.

msg

Character vector to be used as error message. If empty or NULL, the conditionMessage of the issued warning is used.

...

Optional further arguments to tryCatch.

domain

Passed to stop (if a warning occurs).

Value

The result of expr (if no error occurs).

See Also

base::tryCatch base::stop base::options

Other coding-functions: L, LL, assert, case, check, collect, contains, flatten, listing, map_names, map_values, set, sql, unnest

Examples

1
2
3
4
(x <- try(must(as.numeric(c("1", "2", "3"))), silent = TRUE))
stopifnot(identical(x, c(1, 2, 3)))
(x <- try(must(as.numeric(c("1", "x", "3"))), silent = TRUE))
stopifnot(inherits(x, "try-error"))

pkgutils documentation built on May 2, 2019, 5:49 p.m.

Related to must in pkgutils...