2

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.