General suggestions for debugging in R -


I get an error when I use an R function that I have written:

  Warning message: 1: glm.fit: Algorithm 2: glm.fit: Algorithm is not found  

What I did:

  1. Step through function
  2. Adding a print to find out the line that is causing an error suggests two functions that should not use glm.fit . Window () and save () .

In my normal view, by the command and function line, when I can find the exception, print and stop Till i step up

However, it is not clear to me that the use of those techniques comes from where this error code comes from. I'm also not sure whether the code working inside the code depends on glm.fit . How can I go about diagnosing this problem?

I will say that debugging is an art, so there is no clear silver bullet in any language debugging There are good strategies for them, and they apply here (e.g., for example, the first thing is that reproduction of the problem ... if you can not do this, you get more information Need to do (like with logging) once you can reproduce it, you can

Instead of "move," I would say that my favorite debugging routine is:

  1. When there is an error So, the first time I do that, the call stack trace tells you where the error happened, which is particularly useful if you have many nested functions.
  2. Next I'll set the option (error = ok) ; It switches quickly in browser mode, where An error occurs, so you can browse workspace from there.
  3. If I still do not have enough information, then I usually use the debug () line from the script line Through function and phase

The best new move in R 2.10 (when working with script files) is findLineNum () and setBreakpoint () Uses works.

As a last commentary: Depending on the error, it is very useful to set try () or tryCatch () ( Especially working with S4 classes)

There are many suggestions in these related questions:

  • This provides a lot of suggestions:


Comments