tryCatch.W.E | R Documentation |
Catches and saves both warnings (warning
) and errors
(stop
) and in the case of a warning, also the
computed result.
tryCatch.W.E(expr)
expr |
expression to be evaluated, typically a function call. |
This function is particularly useful in large(r) simulation studies to check all computations and guarantee their correctness.
list
with components
value |
value of |
warning |
warning message (see |
Marius Hofert and Martin Maechler, based on hints from Luke Tierney and Bill Dunlap, see https://stat.ethz.ch/pipermail/r-help/2010-December/262626.html.
see simsalapar-package
.
the base function tryCatch()
and
demo(error.catching)
. Also, doCallWE()
, of which
tryCatch.W.E()
is the “workhorse”.
## Adapted from demo(error.catching) :
str(r1 <- tryCatch.W.E( log( 2 ) ) )
str(r2 <- tryCatch.W.E( log(-1 ) ) )
str(r3 <- tryCatch.W.E( log("a") ) )
stopifnot(is.null(r1$warning),
is.na (r2$value), inherits(r2$warning, "warning"),
is.null(r3$warning), inherits(r3$value, "error"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.