Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you know which functions in R are flagged for debugging?

Tags:

r

debugging

I've been using debug() more often now, but sometimes I wonder which functions have been flagged for debugging. I know that you can use isdebugged() to find out if a particular function is flagged. But is there a way for R to list all the functions that are being debugged?

like image 337
andrewj Avatar asked Oct 23 '09 17:10

andrewj


People also ask

Which function is useful for debugging?

Simple Use of GDB A debugger is a program that runs other programs, allowing its user to exercise some degree of control over these programs, and to examine them when things go amiss. In this course, we will be using GDB, the GNU debugger1.

How do you debug a function in RStudio?

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

What does the debug command R stand for and what does it do?

The function debug() in R allows the user to step through the execution of a function, line by line. At any point, we can print out values of variables or produce a graph of the results within the function.


2 Answers

This is convoluted, but it works:

 find.debugged.functions <- function(environments=search()) {
    r <- do.call("rbind", lapply(environments, function(environment.name) {
    return(do.call("rbind", lapply(ls(environment.name), function(x) {
          if(is.function(get(x))) {
             is.d <- try(isdebugged(get(x)))
             if(!(class(is.d)=="try-error")) {
                return(data.frame(function.name=x, debugged=is.d))
             } else { return(NULL) }
          }
       })))
     }))
     return(r)
 }

You can run it across all your environments like so:

find.debugged.functions()

Or just in your ".GlobalEnv" with this:

 > find.debugged.functions(1)
             function.name debugged
 1 find.debugged.functions    FALSE
 2                    test     TRUE

Here I created a test function which I am debugging.

like image 85
Shane Avatar answered Sep 21 '22 02:09

Shane


Unless you wanted to get into something like writing a function to fire everything through isdebugged(), I don't think you can.

In debug.c, the function do_debug is what checks for the DEBUG flag being set on an object. There are only three R functions which call the do_debug C call: debug, undebug and isdebugged.

like image 44
geoffjentry Avatar answered Sep 24 '22 02:09

geoffjentry