【问题标题】:can't step into function calls or loops in Rstudio无法进入 Rstudio 中的函数调用或循环
【发布时间】:2021-12-03 19:16:25
【问题描述】:

我无法进入函数调用或 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)))

当我将我的 cursur 放在第一个 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.tstatFALSE。但它仍然是NULL

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

【问题讨论】:

    标签: r debugging rstudio step


    【解决方案1】:

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

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

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

    1. 不要设置 rstudio 断点,而是在代码中添加它们:在您希望中断的位置添加 browser() 调用。

    【讨论】:

    • 非常同意在函数中添加browser()而不是使用IDE的点击功能。
    • 谢谢你,Ofek 和杰西卡。刚看到你的建议。祝您假期愉快!
    • @JasperC。如果您认为某个答案令人满意,请接受(在您的其他问题中也是如此)
    • 感谢您的善意提醒
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    相关资源
    最近更新 更多