Question

I have a script that I run from the commandline, like

Rscript example.R

and I'd like to have it tell me some debugging information when it exits. If I don't do anything special, if it hits an error, it exits, right there, and I see the error message. So, I added

options(error=traceback)

and then it gave me not only the error message but the stack at the time of the error, very useful. Great.

But now the script continues on through to the end, tossing up a lot more errors. Why does setting the error change Rscript's behaviour on encountering an error? How do I get it to just exit after the first error, as before?

Était-ce utile?

La solution

Ah-ha. The trick is to call q(). In the help for dump.frames:

   options(error = quote({dump.frames(to.file = TRUE); q()}))

and to use traceback (and function instead of quote),

   options(error = function(){  traceback(); q()} )

would do it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top