I would like to step through, using debug()
or trace()
, a function that was not exported. For example, how can I do it for vcov.polr
of the package MASS
, which is called from the function polr
. polr
is exported, but vcov.polr is not.
That is, when I run polr
, I would like the debug browser to start once the code enters vcov.polr
.
R file corresponding to the code you want to debug, it's easy to use editor breakpoints or browser() to add breakpoints to it. Sometimes, however, you don't have the source file for the code you want to debug. When this is the case, you can set a debug flag on the function you want to debug.
R provides a number of tools for debugging: traceback() debug() browser() trace() recover() 140.776 Statistical Computing R: Debugging Page 3 traceback() When an R function fails, an error is printed to the screen. Immediately after the error, you can call traceback() to see in which function the error occurred.
Interactively examining functions with debug() and debugonce() The 2 key functions we will be using for our interactive investigation of code are debug() and debugonce() .
Q to stop debug mode, terminate the function, and return to the R prompt.
try
debug(MASS:::vcov.polr)
note that three colon :::
make the hidden object in a package visible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With