I'm debugging R code with browser(). The function pauses the execution of the current R script and allows for inspection. Is it possible to enable/disable the debug mode on the fly, during the execution? With large scripts it would be very handy.
Thanks
Your question prompted me to read ?browser. The documentation says you can use the expr= argument to browser to create (the illusion) of conditional debugging. That, combined with a global option should give you what you want.
foo <- function(x) {
browser(expr=isTRUE(getOption("myDebug")))
mean(x)
}
foo(1:10)
options(myDebug=TRUE)
foo(1:10) # invokes browser
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