无法单步执行 Rstudio 中的函数调用或循环

问题描述 投票:0回答:1

我无法单步执行函数调用或 Rstudio 中的 for 循环。

for (i in seq_len(max(last))) {
    r = normdata$.return[smpls[[i]]]
    m = normmat(i)
    for (j in which(i <= last)) {
        x = lm.fit(cbind(intercept = 1, m[, avail[i, ] & include[last[j], ], drop = F]), r)
        temp[[j]][[i]] = if (!calc.tstat) 
        cbind(Estimate = coef(x))
        else {
            terms = terms(as.formula(paste(fieldmap["return"], paste(names(coef(x)), collapse 
            =" + "), sep = " ~ ")))
            coef(summary.lm(structure(modifyList(x, list(terms = terms)), class = "lm")))[, 
            1:2, drop = F]
        }
    }
}

f = function(l, i, flip) t(sapply(l[!sapply(l, is.null)], 
    function(x) setNames(x[, i][fields], fields) * (if (flip) sign else 1)))

当我将光标放在第一个 for 循环行并点击运行时,它会忽略两个 for 循环内的断点并退出到 f= 函数行。在控制台上,我可以看到:

Browse[9]> max(last) [1] 131

Browse[9]> j
[1] 1

Browse[9]> i
[1] 1

Browse[9]> temp[[j]][[i]]
NULL

Browse[9]> coef(x)
    intercept        BY_FY0        CY_FY0        CY_NTM        DY_NTM EBITDA_EV_FY0 EBITDA_EV_NTM        EY_FY0        EY_NTM       FUND_PB 
-7.236841e-10  1.121348e-01 -6.650536e-02  1.198634e-02 -5.849855e-02  8.291955e-02 -3.586112e-02 -6.218132e-02  1.936980e-01 -1.064521e-01 
          IRR SAL_YIELD_NTM 
-3.522072e-02  6.294885e-02 

Browse[9]> calc.tstat
[1] FALSE

我期望

temp[[1]][[1]]
设置为
coef(x)
,因为
calc.tstat
FALSE
。但它仍然存在
NULL

有人可以告诉我如何唤醒我的 Rstudio 吗?或者我需要叫醒电话?

r debugging rstudio
1个回答
3
投票

如果无法访问您的

normdata
对象,我们无法调查您的确切问题。两个一般性建议:

  1. 在运行代码之前,请在控制台运行以下代码:
compiler::enableJIT(0)

这有时会使 RStudio 的 IL 到源的匹配更加准确。

  1. 不要设置 rstudio 断点,而是在代码中添加它们:在您想要中断的位置添加
    browser()
    调用。
© www.soinside.com 2019 - 2024. All rights reserved.