rbenchmarkingtimingprofvis

How can I extract the data from profvis in R?


I'm using profvis to profile my functions in R, but I want to extract specific timings for subfunctions. For example if I run

a = profvis({    dat <- data.frame(
        x = rnorm(5e4),
        y = rnorm(5e4)
    )
    plot(x ~ y, data = dat)
    m <- lm(x ~ y, data = dat)
    abline(m, col = "red")
})

How do I extract the value of the timings for the subfunctions?


Solution

  • Extending on User @Roland's answer.

    The last syllable of profvis is vis. I suspect it is short for "visualisation". Your question leaves the impression that you are looking for a table. Staying in base R, we can extend the example given in help(summaryRprof) like

    Rprof(tmp <- tempfile())
    # your example from profvis examples 
    dat <- data.frame(
        x = rnorm(5e4),
        y = rnorm(5e4))
    plot(x ~ y, data = dat)
    m <- lm(x ~ y, data = dat)
    abline(m, col = "red")
    Rprof(NULL)
    r = summaryRprof(tmp)
    unlink(tmp)
    
    > r
    $by.self
                 self.time self.pct total.time total.pct
    "deparse"         0.08    44.44       0.08     44.44
    "plot.xy"         0.08    44.44       0.08     44.44
    ".External2"      0.02    11.11       0.02     11.11
    
    $by.total
                   total.time total.pct self.time self.pct
    "do.call"            0.18    100.00      0.00     0.00
    "plot.default"       0.18    100.00      0.00     0.00
    "plot.formula"       0.18    100.00      0.00     0.00
    "plot"               0.18    100.00      0.00     0.00
    "deparse"            0.08     44.44      0.08    44.44
    "plot.xy"            0.08     44.44      0.08    44.44
    "deparse1"           0.08     44.44      0.00     0.00
    "paste"              0.08     44.44      0.00     0.00
    ".External2"         0.02     11.11      0.02    11.11
    "plot.new"           0.02     11.11      0.00     0.00
    
    $sample.interval
    [1] 0.02
    
    $sampling.time
    [1] 0.18
    

    You probably want r$by.total.