Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug unexported functions from required packages?

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. 
like image 472
biocyberman Avatar asked Jul 06 '15 20:07

biocyberman


People also ask

How do I debug a package in R studio?

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

How to understand debugging?

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.

What does a debugger do?

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.


1 Answers

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

like image 116
Gavin Simpson Avatar answered Nov 12 '22 19:11

Gavin Simpson