Continue executing after browser()

时光毁灭记忆、已成空白 提交于 2020-01-11 10:32:10

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/8142339/continue-executing-after-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!