In R, the Rprof
function allows users to obtain process information by statistical profiling meaning that it collects call information over intervals of time. The profr package gives a convenient rapper over the Rprof
function in R and returns information in a data frame and allows you to represent the call stack graphically.
We would like to look at the call stack in the MackChainLadder
function in the ChainLadder package:
# Load the packages
require(profr)
require(ChainLadder)
# Run the profiler
p <- profr(MackChainLadder(auto[[3]]), 0.005)
head(p)
level g_id t_id f start end n leaf time source
8 1 1 1 MackChainLadder 0.000 0.040 1 FALSE 0.040 ChainLadder
9 2 1 1 chainladder 0.000 0.020 1 FALSE 0.020 ChainLadder
10 2 2 1 predict.ChainLadder 0.020 0.035 1 FALSE 0.015 <NA>
11 2 3 1 Mack.S.E 0.035 0.040 1 FALSE 0.005 <NA>
12 3 1 1 lapply 0.000 0.020 1 FALSE 0.020 base
13 3 2 1 predict.TriangleModel 0.020 0.035 1 FALSE 0.015 <NA>
plot(p)
Be aware however that since it is a statistical profiler, you will get a different answer each time you run it on the same process and the granularity will also vary depending on the time interval you choose (it will vary anyway!).