A function, in a package I am using is giving me not so informative errors. I don't know what is going on. This function is called internally by the function I call. Something like this:
myres <- the.func(x)
the.func <-function(x){
unexported.func(x)
}
How do I debug unexported.func
?
Using debug
doesn't work:
>debug(unexported.func)
Error in debug(undexported.func) : object 'unexported.func' not found
Update: Currently I do nested debug like the following. But I find it inconvenient:
>debug(the.func) # Initiate debugging for the outer function, so I get unexported.func loaded.
>myres <- the.func(x)
Browse[2]>debug(unexported.func) # Now I can call debug with this.
You can do this in RStudio by clicking to the left of the line number in the editor, or by pressing Shift+F9 with your cursor on the desired line. We call this an “editor breakpoint”. Editor breakpoints take effect immediately and don't require you to change your code (unlike browser() breakpoints, below).
Debugging means to run your code step by step in a debugging tool like Visual Studio, to find the exact point where you made a programming mistake. You then understand what corrections you need to make in your code and debugging tools often allow you to make temporary changes so you can continue running the program.
A debugger is a software tool that can help the software development process by identifying coding errors at various stages of the operating system or application development. Some debuggers will analyze a test run to see what lines of code were not executed.
You can access an unexported function via the :::
(triple-colon) operator, prefacing it with the package namespace name (i.e. the package name).
Assuming the pkgA contains the unexported function unexported.func()
, we would set the debugging flag on unexported.func()
using:
debug(pkgA:::unexported.func)
If you don't know which package (hence namespace) to use for a given unexported function, you can always determine this using getAnywhere()
.
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