我有一个涵盖多个函数(和文件)的精心设计的脚本。出于调试目的,我需要将浏览器调用嵌入到各种角落和缝隙中。当我想修复某些问题时,我希望在不调试的情况下运行整个过程,因此避免浏览器调用,因为注释掉所有浏览器调用将意味着我需要付出相当大的努力。 R 聊天中的 @mdsumner 建议以非交互模式运行脚本(即在 Windows 上使用 Rscript.exe),但我会受益于在我的控制台中完成此操作,以便能够访问例如 traceback
。我已经浏览了浏览器文档,但找不到接近我想要实现的目标的选项。有什么建议吗?
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?
发布评论
评论(3)
以下是三种可能性:
1) 覆盖浏览器命令。将此命令添加到全局工作区以关闭浏览器命令:
并将其重新打开
这可能是最简单的,但由于
browser
变量留在全局环境中而有点难看。接下来的两个解决方案稍长一些,但使用选项来代替,这样就不会在全局环境中引入新变量。此外,如果没有设置选项,则不会进行任何调试,因此如果您想要调试,只需设置一个选项。
if
解决方案可能比expr
解决方案更快,尽管它可能并不重要。2) 使用 expr= 参数和选项。将每个浏览器命令替换为:
,然后将
"Debug"
选项定义为TRUE
以打开调试。或将其设置为其他内容或将其删除以关闭调试:
3) 将 if 与选项一起使用。将每个浏览器命令替换为:
,然后设置
Debug
选项或不像之前那样设置。Here 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.定义全局逻辑值
,然后使用
browser()
代替Define global logical value
and then instead of
browser()
use我认为这归结为调试功能的细致使用。如果您想有选择地控制
browser()
的使用,请将其放入if
中,以便您启用或禁用该函数的调试。当您希望调用浏览器时,请明确显示,例如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 like