如何在 RStudio 中为包函数设置断点 [英] How to set breakpoints for package functions in RStudio

查看:36
本文介绍了如何在 RStudio 中为包函数设置断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要复制此错误,您必须首先安装包 MARSS.我还包括用户指南.

To replicate this error you must first install the package MARSS. I also include the user guide.

https://cran.r-project.org/web/packages/MARSS/vignettes/UserGuide.pdf

第 35 页上的示例可以使用

The example on page 35 can be called with the

dat = t(harborSealWA)
dat = dat[2:nrow(dat),]
debugonce(MARSSkem)
kemfit = MARSS(dat)

在 RStudio 中触发 MARSSkem 的 debugmode 时,您会发现无法设置断点!屏幕顶部还有一条调试消息说:调试位置是近似的,因为源代码不可用".我想这就是我不能设置断点的原因!

When debugmode is triggered for MARSSkem in RStudio, you will find that it is not possible to set breakpoints! There is also a debug message at the top of the screen saying: "Debug location is approximate because source source code is not available". I assume this is why I can't set the breakpoints!

问题是我试图定位的错误(在所示的简单示例中不存在)是在第 55 次迭代中发现的,并且每次迭代都包含多个 for 循环,每个循环有 100 个循环!手动步进根本不实用!

The problem is the error I am trying to locate (which is not present in the simple example shown) is found on 55th iteration and each iteration includes several for loops with 100 loops each! To step though by hand is simply not practical!

Q1.) 有没有办法在 R studio 中为这个函数设置断点?

Q1.) Is there a way to set breakpoints for this function in R studio?

Q2.) 如果不是,我找到这个问题的最佳选择是什么?(理想情况下,我不想弄乱包源代码,但如果它是唯一的选择,我会这样做)

Q2.) If not what is my best option to locate this problem? (Ideally I don't want to go messing around with the package source code but I will if its the only option)

谢谢

巴兹

推荐答案

最简单的方法(我认为)是制作您自己的函数副本,获取它,然后使用断点.

The easiest way to do this (I think) is to make your own copy of the function, source it, and then play around with breakpoints.

要做到这一点:

View(MARSS)

您应该会看到源弹出窗口.现在将其复制粘贴到一个带有 mymarss <- 的新脚本中,将其保存(可能是 mymarss.R),并获取它.

You should see the source pop-up. Now copy paste it, into a new script with mymarss <- at the very start, save it (maybe as mymarss.R), and source it.

source(mymarss.R)

现在你可以像往常一样调试了:

Now you can debug it like normal:

dat = t(harborSealWA)
dat = dat[2:nrow(dat),]
debugonce(mymarss)
kemfit = mymarss(dat)

并且您可以自由添加/删除断点等

And you can freely add/Remove breakpoints etc etc.

这篇关于如何在 RStudio 中为包函数设置断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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