Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continue executing after browser()

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

like image 815
Mulone Avatar asked Feb 10 '26 09:02

Mulone


1 Answers

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
like image 111
Joshua Ulrich Avatar answered Feb 15 '26 00:02

Joshua Ulrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!