且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

R Studio 中奇怪的调试结果

更新时间:2023-02-18 12:08:33

大多数 R 包不包含包源代码的副本(keep.source 选项控制此行为;您可以阅读更多关于它这里).当您从这种包中调试代码时,RStudio 必须猜测代码最初的样子以及当前执行点在该代码中的位置.此过程包括一些启发式方法,并且偶尔会误解执行点.所以你看到的不是实际执行点的跳跃,而是 RStudio 对它在解析后的代码中的位置做出了错误的猜测.

Most R packages don't include copies of the package's source code (the keep.source option controls this behavior; you can read more about it here). When you debug code from this kind of package, RStudio has to guess at both what the code looked like originally and where the current execution point is in that code. This process includes some heuristics and does occasionally misinterpret the execution point. So what you're seeing is not the actual execution point jumping around, but RStudio making the wrong guess about where it is in the deparsed code.

来自您自己的 R 脚本(以及来自带有 keep.source 的包)的代码具有源引用(请参阅 R 期刊文章) 允许 RStudio 精确排列代码和执行点.

Code from your own R scripts (and from packages with keep.source) have source references (see R journal article) which allow RStudio to line up the code and execution point precisely.

我无法在您的示例中重现这一点(它似乎引用了一个未声明的变量 m);如果你能解决这个问题并将其发送给我(rstudio dot com 的乔纳森),我会看看我们是否可以改进启发式方法,使这种情况更好.

I wasn't able to reproduce this with your example (it appears to reference a variable m that it doesn't declare); if you can resolve that and send it to me (jonathan at rstudio dot com) I'll see if we can improve the heuristics so this case works better.