| tryCatch.W.E {simsalapar} | R Documentation |
Catching and Storing Warnings and Errors Simultaneously
Description
Catches and saves both warnings (warning) and errors
(stop) and in the case of a warning, also the
computed result.
Usage
tryCatch.W.E(expr)
Arguments
expr |
expression to be evaluated, typically a function call. |
Details
This function is particularly useful in large(r) simulation studies to check all computations and guarantee their correctness.
Value
list with components
value |
value of |
warning |
warning message (see |
Author(s)
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.
References
see simsalapar-package.
See Also
the base function tryCatch() and
demo(error.catching). Also, doCallWE(), of which
tryCatch.W.E() is the “workhorse”.
Examples
## 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"))
[Package simsalapar version 1.0-12 Index]