warnErrList
Summarize and Replace Errors in Loops over tryCatch()
Description
Given the result of lapply(x, function(x)tryCatch(analyze(x), error=function(e)e)),
replaces all the error entries with a value. If errors occur, tabulates
the error messages and warns the user.
Usage
warnErrList(x, warn = TRUE, errValue = NULL)
Arguments
x |
a list. Usually this list is the result of a function such as lapply. Entries of
class "error", generally made by a call to tryCatch(..., error=function(e)e),
are dealt with by this function.
|
warn |
a logical value.
- If TRUE, and if there are any error entries in x, then
warn the user, showing a tabulation of the error messages.
- If FALSE, do not emit a warning.
In either case, if there are error entries, then
warnErrList attaches the attribute "warningMsg" containing
the warning that could have been emitted.
|
errValue |
a value with which to replace all of the components of x of class "error".
|
Value
- If there are no error entries in x, then x is returned unaltered.
Any error entries are replaced by errValue.
- If there are any error entries, then
the attribute "warningMsg", containing a sorted tabulation of the error messages,
is attached to the return value.
Note
This function can be helpful for running simulations were some input values cause errors.
See Also
Examples
d <- data.frame(X=log(1:6), Y=1:6)
fits <- lapply(c(0,0,1,4,5,6),
function(nrows) tryCatch(coef(lm(data=d[seq_len(nrows),], Y ~ X, singular.ok=FALSE)),
error=function(e)e))
simplify2array(warnErrList(fits, errValue=c(NA_real_, NA_real_)))