Dear R experts---I may have asked this in the past, but I don't think I figured out how to do this. I would like to execute traceback() automatically if my R program dies---every R programI ever invoke. I guessed that I could have wrapped my entire R code into tryCatch( ... oodles of R code , error = function(e) traceback(), finally = cat("done") } but the traceback docs tell me that this does not generate a traceback(). in a perfect world, I would stick this into my .Rprofile and forget about it. in an super-perfect world, it would be an option() that I just don't know yet... possible? /iaw
Hi Ivo, Does this do what you want? options(error = function(x) base::traceback()) Cheers, Josh On Thu, Nov 24, 2011 at 8:22 PM, ivo welch <ivo.welch at gmail.com> wrote:> Dear R experts---I may have asked this in the past, but I don't think > I figured out how to do this. ?I would like to execute traceback() > automatically if my R program dies---every R programI ever invoke. ?I > guessed that I could have wrapped my entire R code into > > tryCatch( > > ... oodles of R code > > , > error = function(e) traceback(), > finally = cat("done") > } > > but the traceback docs tell me that this does not generate a > traceback(). ?in a perfect world, I would stick this into my .Rprofile > and forget about it. ?in an super-perfect world, it would be an > option() that I just don't know yet... > > possible? > > /iaw > > ______________________________________________ > R-help at 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. >-- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/
On 11-11-24 11:22 PM, ivo welch wrote:> Dear R experts---I may have asked this in the past, but I don't think > I figured out how to do this. I would like to execute traceback() > automatically if my R program dies---every R programI ever invoke. I > guessed that I could have wrapped my entire R code into > > tryCatch( > > ... oodles of R code > > , > error = function(e) traceback(), > finally = cat("done") > } > > but the traceback docs tell me that this does not generate a > traceback(). in a perfect world, I would stick this into my .Rprofile > and forget about it. in an super-perfect world, it would be an > option() that I just don't know yet... > > possible?Sure, but it's a little bit of work. The traceback doesn't exist at that point, so you can't print it. But you could construct it yourself. This comes close: options(error=function(e) print(traceback(sapply(sys.calls(), deparse)))) You may want something a little fancier so it doesn't print itself, and I think the order may be the reverse of the usual order, but I said it would be a little bit of work. Duncan Murdoch