Search code examples
rdebuggingrstudio

can't step into function calls or loops in Rstudio


I can't step into function calls or into the for loop in Rstudio.

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)))

When I put my cursur on the first for loop line and hit run, it ignores my breakpoints inside both for loops and exits to the f= function line. On the Console, I can see:

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

I'm expecting temp[[1]][[1]] is set to coef(x), as calc.tstat is FALSE. But it remains NULL.

Could someone shed me some light on how to wake up my Rstudio please? Or I need a wakeup call?


Solution

  • Without access to your normdata object we can't investigate your exact problem. Two general suggestions:

    1. Before running your code, run this at the console:
    compiler::enableJIT(0)
    

    This occasionally makes RStudio's IL-to-source matching more accurate.

    1. Instead of setting rstudio breakpoints, add them in code: add browser() calls where you wish to break.