我的前两个建议非常基本:(1)将函数调用包装在try()
(经常提供有关 S4 类的更多信息)和 (2) 调用traceback()
抛出错误后(有时可以提示问题真正发生的位置)。
Calling debug()
在这种情况下没有帮助,所以你需要使用trace
or browser
。从调试帮助页面:
"In order to debug S4 methods (see Methods), you need to use trace, typically
calling browser, e.g., as "
trace("plot", browser, exit=browser, signature = c("track", "missing"))
S4 类可能很难使用;其中的一个例子是评论the debug package http://cran.r-project.org/web/packages/debug/index.html文档(关于使用mtrace()
与 S4 课程):
"I have no plans to write S4 methods, and hope not to have to
debug other people’s!"
A 最近在 R-Help 上提出了类似的问题 http://old.nabble.com/debugging-S4-methods-td25697205.html。邓肯·默多克的建议:
"You can insert a call to browser() if you want to modify the source. If
you'd rather not do that, you can use trace() to set a breakpoint in it.
The new setBreakpoint() function in R 2.10.0 will also work, if you
install the package from source with the R_KEEP_PKG_SOURCE=yes
environment variable set. It allows you to set a breakpoint at a
particular line number in the source code."
我以前从未这样做过(并且它需要 R 2.10.0),但您可以尝试从源代码安装R_KEEP_PKG_SOURCE=yes
.
顺便说一下,您可以使用NADA 的 CRAN 镜像 https://github.com/cran/NADA在github上浏览源码。