I have an elaborate script that spans multiple functions (and files). For debugging purposes I need to embed browser
calls into all sorts of nooks and crannies. When I presumably fix something, I want to run the whole thing without debugging, ergo avoiding browser
calls because commenting out all browser calls would mean a considerable effort from my part. @mdsumner on R chat suggested running the script in non-interactive mode (i.e. using Rscript.exe on Windows) but I would benefit from having that done in my console, to be able to access for instance traceback
. I have gone through browser docs and I can find no option that would come close to what I'm trying to achieve. Any suggestions?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
I think this just comes down to nuanced use of a debugging function. If you want to selectively control the use of
browser()
, put it inside anif
that lets you enable or disable debugging for the function. When you want browser to be called, make that explicit likeHere are three possibliities:
1) Overwrite browser command. Add this command to your global workspace to turn the browser commands off:
and to turn it back on
This is probably the easiest but is a bit ugly due to the
browser
variable being left in the global environment.The next two solutions are slightly longer but use options instead so that no new variables are introduced into the global environment. Also they are such that if no options are set then no debugging is done so you only have to set an option if you want debugging. The
if
solution may be faster than theexpr
solution although its likely not material.2) Use expr= argument with option. Replace each browser command with:
and then define the
"Debug"
option to beTRUE
to turn debugging on.or set it to something else or remove it to turn debugging off:
3) Use if with an option. Replace each browser command with:
and then set the
Debug
option or not as in the prior point.Define global logical value
and then instead of
browser()
use