R中的高级调试功能? [英] Advanced debugging functionality in R?

查看:108
本文介绍了R中的高级调试功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R中是否有任何软件包和/或hack可以为调试器提供更多功能?我正在寻找:

Are there any packages and/or hacks in R that give the debugger more functionality? I'm specifically looking for:

  1. 遍历整个循环的能力
  2. 无需调用debug就可以进入函数调用的功能
  3. 能够在我已经在调试器中时设置断点或有效地在代码中插入browser调用的能力(即,这样,如果我在调试过程中发现我想要断点的地方,则不必退出并重新运行再次整个功能)
  1. The ability to step over a whole loop
  2. The ability to step into function calls without calling debug on them also
  3. The ability to set breakpoints or effectively insert browser calls into the code while I am already in the debugger (i.e. so that if I figure out during debugging where I want a breakpoint I don't have to quit and rerun the whole function again)

等等.

编辑时:我在emacs/ess中运行了R,因此,如果有任何ess技巧可以提供帮助,我也会对此感兴趣.

On edit: I run R out of emacs/ess, so if there's any ess trick that can help, I'd be interested in that also.

推荐答案

这称为ess-tracebug.在 C-c C-t ess-dev-map上可以使用此功能以及其他开发功能.按 C-c C-t C-h 可以查看其中的内容.

This is called ess-tracebug. This and a bunch of other functionality for development is available on C-c C-t ess-dev-map. Press C-c C-t C-h to see what is there It should be self explanatory.

请参阅ESS手册的部分. ess-tracebug 的原始项目页面以获取基本信息.有几种断点类型可用,您可以添加自己的断点并使其执行任意R代码.错误操作和记录器也是如此.

See this section of ess manual and the original project page of ess-tracebug for basic stuff. There are several breakpoint types available and you can a add your own breakpoints and make them execute arbitrary R code. Same for on-error actions and loggers.

那里也有教程.

关于你的观点.

  1. 默认情况下,您无法跳过整个循环(R不允许这样做,afaik).但是您可以使用M-N跳过多个迭代,或者在循环后放置一个断点,并在遇到循环时运行M-C(尽管您需要事先评估/评估).还有M-U跳到外部呼叫帧.

  1. You cannot jump over the whole loop by default (R doesn't allow that, afaik). But you can jump over several iterations with M-N or place a breakpoint after the loop and run M-C when you hit a loop (you need eval/source in advance though). There is also M-U to jump to the outer call frame.

是的, C-c C-t C-d 标记您想要调试器使用的任何函数或方法.它足够聪明,还可以显示从当前调试上下文可见的内部/命名空间函数.有关外观,请参见此处.

Yes, C-c C-t C-d to mark whatever function or method you want for a debugger. It is smart enough to also show internal/namespace functions visible from the current debugging context. See here for how it looks.

您可以如上面的(2)中所示标记要调试的功能,或者插入断点并评估该功能.评估的效果将取决于您的评估方式.如果它是一个简单的求值(例如C-c C-c),则该函数将被派生到当前上下文中,这可能是您想要的,但很可能不是.如果开发人员处于活动状态并且该功能是所开发软件包的一部分,则评估在名称空间/软件包级别进行,因此您将立即安装断点.

You can either mark the function for debugging as in (2) above, or insert the breakpoint and evaluate the function. The effect of the evaluation will depend on how you do it. If it is a simple evaluation (like C-c C-c) then the function will be sourced into the current context, which might be what you want but most likely not. If developer is active and the function is part of the developed package(s), then the evaluation happens at namespace/package level, so you will get your breakpoints installed immediately.

您还可以使用 C-c C-t o 切换断点.效果是立竿见影的,您无需再次进行源/评估功能.

You can also toggle breakpoints with C-c C-t o. The effect is immediate, you won't need to source/evaluate your function again.

最后,如果您已经在调试环境中,那么 C-c C-t C-d 可能是最干净的调试函数/方法的方法.否则,只需设置一个断点并评估/获取代码即可.

To conclude, C-c C-t C-d is probably the cleanest way to debug a function/method if you already in the debugging context. Otherwise, just set a breakpoint and evaluate/source the code.

可能会在将来动态添加断点,但它将增加一层额外的复杂性,而IMO不会获得太大收益.

On the fly breakpoints might be added in the future, but it will add an additional layer of complexity with not much gain IMO.

这篇关于R中的高级调试功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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