must {pkgutils} | R Documentation |
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).
must(expr, msg = NULL, ..., domain = NULL)
expr |
R expression to evaluate. |
msg |
Character vector to be used as error message.
If empty or |
... |
Optional further arguments to
|
domain |
Passed to |
The result of expr
(if no error occurs).
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
(x <- try(must(as.numeric(c("1", "2", "3"))), silent = TRUE))
## [1] 1 2 3
stopifnot(identical(x, c(1, 2, 3)))
(x <- try(must(as.numeric(c("1", "x", "3"))), silent = TRUE))
## [1] "Error : NAs introduced by coercion\n"
## attr(,"class")
## [1] "try-error"
## attr(,"condition")
## <simpleError: NAs introduced by coercion>
stopifnot(inherits(x, "try-error"))