tryCatch2 | R Documentation |
Modification of tryCatch
which allows recovery from warnings
and messages while returning the value from expr
. Note that the
return value from errors and interruptions is NULL
.
tryCatch2(expr, ..., simplify = TRUE)
expr |
an expression |
... |
ignored |
simplify |
logical; if |
If expr
is evaluated with no errors, warnings, messagess, or
interruptions, then only the value of expr
is returned unless
simplify = FALSE
in which case a list with the return value.
If expr
results in one of the above conditions, then a list with
the value of expr
along with an additional element for the
condition(s) which can be accessed with $warning
, $error
,
etc.
Martin Morgan, Jan Gorecki, Robert Redd (modifications)
tryCatch
; logR::tryCatch2
;
https://stackoverflow.com/q/4948361/2994949;
logR github repo
## returns value if no errors, warnings, etc
tryCatch2(1)
tryCatch2(1, simplify = FALSE)
tryCatch2(stop('halt at once!'))
tryCatch2({warning('warning'); message('message'); 1})
## compare
tryCatch({warning('this is your warning...'); 1}, warning = function(w) w)
tryCatch2({warning('this is your warning...'); 1})
tryCatch({message('calculating...'); 1}, message = function(m) m)
tryCatch2({message('calculating...'); 1})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.