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
So browser()
, traceback()
and debug()
walk into a bar, but trace()
waits outside and keeps the motor running.
By inserting browser
somewhere in your function, the execution will halt and wait for your input. You can move forward using n (or Enter), run the entire chunk (iteration) with c, finish the current loop/function with f, or quit with Q; see ?browser
.
With debug
, you get the same effect as with browser, but this stops the execution of a function at its beginning. Same shortcuts apply. This function will be in a "debug" mode until you turn it off using undebug
(that is, after debug(foo)
, running the function foo
will enter "debug" mode every time until you run undebug(foo)
).
A more transient alternative is debugonce
, which will remove the "debug" mode from the function after the next time it's evaluated.
traceback
will give you the flow of execution of functions all the way up to where something went wrong (an actual error).
You can insert code bits (i.e. custom functions) in functions using trace
, for example browser
. This is useful for functions from packages and you're too lazy to get the nicely folded source code.