Skip to content

interaction of options(error=) and try(): was how to debug a sudden exit in non-interactive mode

1 message · Vadim Ogranovich

#
Hi,

First of all let me thank Prof. Ripley and Peter Dalgaard for their
suggestions about ways to debug my initial problem. Debugger() suggested
by Prof. Ripley could have provided the definitive answer hadn't it
itself be somewhat flaky. Anyway it still helped a lot to pinpoint the
problem.

The problem turned out to be an old R "deficiency" that showed up again
when I used the mgcv package. In Jan 2003 I reported that even when an
error happens inside try() the error handler set by option(error=...)
would still be called (and it shouldn't). If the handler does something
non-local, e.g. quits via q(), then the function is given no chance to
recover. This is precisely what happened in my case.

The mgcv's function get.var() uses try() and then gracefully recovers
from the error, see a verbatim copy below:
get.var <- function (txt, data) 
{
    x <- data[[txt]]
    if (is.null(x)) {
        x <- try(eval(parse(text = txt), data, enclos = NULL), 
            silent = TRUE)
        if (inherits(x, "try-error")) 
            x <- NULL
    }
    x
} 


However inside my .Rprofile I set
if (!interactive()) {
  options(error=quote({dump.frames(to.file=TRUE); q()}))
}
in order to use debugger() later on the dump. (I can no longer do it
since it breaks mgcv).



Back in 2003 I was told that this deficiency would go away when a new
more comprehensive mechanism would be implemented. Has it?

I thought I'd bring it up again since now it affects a recommended
package and therefore is less esoteric than my original example.

Thanks,
Vadim