避免浏览器R中调用 [英] avoiding browser calls in R

查看:183
本文介绍了避免浏览器R中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个跨越多个职能(和文件)一个精心制作的脚本。为了调试目的,我需要嵌入浏览器调入各种角落和缝隙。当我presumably修复的东西,我想运行无需调试整个事情,ERGO避免浏览器呼叫次数,因为注释掉所有浏览器调用将意味着我而言相当大的努力。 R上聊天@mdsumner建议在非交互模式运行脚本(即在Windows上使用Rscript.exe),但我想不必在我的控制台做,才能够访问,例如追踪受益。我已经通过浏览器的文档了,我找不到任何选项,会来接近我想要实现的。有什么建议?

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?

推荐答案

下面有三个possibliities:

Here are three possibliities:

1)覆盖浏览器命令。这个命令添加到您的工作空间的全球打开浏览器的命令关闭:

1) Overwrite browser command. Add this command to your global workspace to turn the browser commands off:

browser <- list

,并重新打开它。

and to turn it back on

rm(browser)

这可能是最简单的,但有点难看,由于浏览器被留在了全球环境变量。

This is probably the easiest but is a bit ugly due to the browser variable being left in the global environment.

接下来的两个解决方案是稍长,但使用的选项,而不是因此没有新的变量引入全球环境。此外,他们是这样的,如果没有设定选项则没有调试完毕,所以你只需要,如果你想调试设置的选项。在如果解决方案可能会比更快EXPR 解决方案,虽然它可能不是物质的。

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 the expr solution although its likely not material.

2)使用EXPR =带选项参数即可。替换为每个浏览器命令:

2) Use expr= argument with option. Replace each browser command with:

browser(expr = isTRUE(getOption("Debug")))

然后定义调试选项是 TRUE 来启用调试。

options(Debug = TRUE)

或将其设置为别的东西或删除它打开调试关:

or set it to something else or remove it to turn debugging off:

options(Debug = NULL)

3)使用,如果一个选项即可。替换为每个浏览器命令:

3) Use if with an option. Replace each browser command with:

if (isTRUE(getOption("Debug"))) browser()

,然后将调试选项,或者还不如在在先点。

and then set the Debug option or not as in the prior point.

这篇关于避免浏览器R中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆