assert {pkgutils} | R Documentation |
A function similar to stopifnot
reporting more
details on vector elements.
assert(cond, orig, msg, quiet = FALSE, ...)
cond |
A logical vector, character scalar or
function. If a character scalar, converted to a function
with |
orig |
Mandatory if |
msg |
When empty or missing, an error message is
constructed automatically in the case of failure.
Otherwise either are |
quiet |
Logical scalar determining the type of
output in case of success (i.e., all values of
|
... |
Optional arguments passed to |
Compared to stopifnot
this function can only
conduct a test on a single object but can report
element-specific details of failures.
The type of return value depends on the values of
quiet
and cond
.
base::stopifnot base::match.fun base::sprintf
Other coding-functions: L
,
LL
, case
,
check
,
collect
, contains
,
flatten
, listing
,
map_names
, map_values
,
must
, set
, sql
,
unnest
stopifnot(assert(function(x) x > 0, 1:10))
(x <- try(assert(function(x) x > 0, -1:8), TRUE))
## [1] "Error : assertion 'function(x) x > 0' failed for '-1'\nassertion 'function(x) x > 0' failed for '0'\n"
## attr(,"class")
## [1] "try-error"
## attr(,"condition")
## <simpleError: assertion 'function(x) x > 0' failed for '-1'
## assertion 'function(x) x > 0' failed for '0'>
stopifnot(inherits(x, "try-error"))