I'm using R-2.3.1 but the code in question is the same in the 01-Oct-2006 snapshot for release 2.4.0. I'd like to evaluate an expression, catching errors and handling them as warnings. My first attempt:
x <- tryCatch(lm(xyzzy), error=warning) didn't work; the error is still treated as an error, not a warning. So I thought, hmmm, the condition is still classed as an "error", how about if I change that: as.warning <- function(e) warning(simpleWarning(e$message,e$call)) x <- tryCatch(lm(xyzzy), error=as.warning) Still no luck. But this works: as.warning <- function(e) .signalSimpleWarning(e$message,e$call) x <- tryCatch(lm(xyzzy), error=as.warning) I think the problem here is that warning() contains the code: withRestarts({ .Internal(.signalCondition(cond, message, call)) .Internal(.dfltStop(message, call)) }, muffleWarning = function() NULL) i.e., the default action is .dfltStop(), not .dfltWarn(). Is this intentional? It seems to make more sense to me for the default action for conditions passed to warning() to be .dfltWarn(), but I may well be misunderstanding something. -- David Hinds ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel