Printing stack trace and continuing after error occurs in R

前端 未结 8 2059
再見小時候
再見小時候 2020-12-08 04:42

I\'m writing some R code that calls other code that may fail. If it does, I want to print a stack trace (to track down what went wrong), then carry on regardless. However, t

8条回答
  •  自闭症患者
    2020-12-08 05:32

    no line numbers but this is the closest I found so far:

    run = function() {
        // Your code here...
    }
    withCallingHandlers(run(), error=function(e)cat(conditionMessage(e), sapply(sys.calls(),function(sc)deparse(sc)[1]), sep="\n   ")) 
    

提交回复
热议问题