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