How about this: test <- function(x) log(x) tryCatch({ #Code that will error test("a") }, finally = { sink(stderr()) traceback() sink() })
If you are running non-interactively, invoke R with the --interactive flag to force it. Saving the code above to test.R, you can see the effect with $ R --interactive < test.R 1> test.out 2> test.err This seems reasonable, but maybe others will say if I'm missing something more automagic. -Matt On Sun, 2010-08-22 at 11:58 -0400, ivo welch wrote: > yes, thank you. is it possible to have it invoked to STDERR > automatically on a program abort? > > /iaw > > On Sun, Aug 22, 2010 at 11:50 AM, Matt Shotwell <shotw...@musc.edu> wrote: > > On Sun, 2010-08-22 at 11:41 -0400, ivo welch wrote: > >> Dear R Wizards---is it possible to get R to show its current call > >> stack (sys.calls()) upon an error abort? I don't use ESS for > >> execution, and it is often not obvious how to locate how I triggered > >> an error in an R internal function. Seeing the call stack would make > >> this easier. (right now, I sprinkle "cat" statements everywhere, just > >> to locate the line where the error appears.) Of course, I would > >> really love to see the line in my program that triggered this, but I > >> have asked this before, and I understand this is too difficult to get > >> into the R language. > > > > The traceback() function will print out the call stack after an error. > > However, you may find the debug() family of functions more useful for > > debugging. Also see the browser() function. > > > > -Matt > > > >> > >> regards, > >> > >> /iaw > >> > >> ---- > >> Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com) > >> > >> ______________________________________________ > >> R-help@r-project.org mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-help > >> PLEASE do read the posting guide > >> http://www.R-project.org/posting-guide.html > >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > Matthew S. Shotwell > > Graduate Student > > Division of Biostatistics and Epidemiology > > Medical University of South Carolina > > > > -- Matthew S. Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.