Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debugging a function in R that was not exported by a package

Tags:

r

debugging

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.

like image 937
Xu Wang Avatar asked Oct 02 '11 08:10

Xu Wang


People also ask

How do I debug code in R?

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.

How do you trace errors in R?

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.

Which function's is are used to examine any object interactively?

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() .

How do I stop debug in R?

Q to stop debug mode, terminate the function, and return to the R prompt.


1 Answers

try

debug(MASS:::vcov.polr)

note that three colon ::: make the hidden object in a package visible.

like image 126
kohske Avatar answered Sep 29 '22 11:09

kohske