You might give pander's evals
function a try which has a custom cache engine.
See the above link for details but in short:
- Enable caching:
evalsOptions('cache', TRUE)
(default value)
- You can set a min.
eval
time in seconds where the results should be cached: evalsOptions('cache.time', 0.1)
(default value)
- Specify where you want to store the cached values and hashes (
disk
vs. R environment
): evalsOptions('cache.mode', 'environment')
(default value)
A short example:
> library(pander)
> # first time run
> system.time(evals('sapply(rep(mtcars$hp, 1e3), mean)'))
user system elapsed
12.269 0.020 12.414
> # second call
> system.time(evals('sapply(rep(mtcars$hp, 1e3), mean)'))
user system elapsed
0.003 0.000 0.003
> # check results any time without recomputing those
> str(evals('sapply(rep(mtcars$hp, 1e3), mean)')[[1]]$result)
num [1:32000] 110 110 93 110 175 105 245 62 95 123 ...
> str(evals('sapply(rep(mtcars$hp, 1e3), mean)'))
List of 1
$ :List of 6
..$ src : chr "sapply(rep(mtcars$hp, 1000), mean)"
..$ result: num [1:32000] 110 110 93 110 175 105 245 62 95 123 ...
..$ output: chr [1:1778] " [1] 110 110 93 110 175 105 245 62 95 123 123 180 180 180 205 215 230 66" " [19] 52 65 97 150 150 245 175 66 91 113 264 175 335 109 110 110 93 110" " [37] 175 105 245 62 95 123 123 180 180 180 205 215 230 66 52 65 97 150" " [55] 150 245 175 66 91 113 264 175 335 109 110 110 93 110 175 105 245 62" ...
..$ type : chr "numeric"
..$ msg :List of 3
.. ..$ messages: NULL
.. ..$ warnings: NULL
.. ..$ errors : NULL
..$ stdout: NULL
..- attr(*, "class")= chr "evals"