General suggestions for debugging in R

后端 未结 13 2190
梦毁少年i
梦毁少年i 2020-11-22 12:26

I get an error when using an R function that I wrote:

Warning messages:
1: glm.fit: algorithm did not converge 
2: glm.fit: algorithm did not converge 
         


        
13条回答
  •  长情又很酷
    2020-11-22 13:15

    I like Gavin's answer: I did not know about options(error = recover). I also like to use the 'debug' package that gives a visual way to step through your code.

    require(debug)
    mtrace(foo)
    foo(1)
    

    At this point it opens up a separate debug window showing your function, with a yellow line showing where you are in the code. In the main window the code enters debug mode, and you can keep hitting enter to step through the code (and there are other commands as well), and examine variable values, etc. The yellow line in the debug window keeps moving to show where you are in the code. When done with debugging, you can turn off tracing with:

    mtrace.off()
    

提交回复
热议问题