문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top