tests/testthat/examples/knitr-examples/101-cache-levels.md

Different cache levels

cache=FALSE or cache=0 means no cache:

Sys.sleep(1)
1 + 1
## [1] 2
plot(cars)

plot of chunk test-cache-a

cache=1 means to save the results from evaluate::evaluate(), and pretend the code has been evaluated; all the output hooks will be applied every time the document is recompiled; note the plots are also saved as display lists, and will be redrawn every time the document is recompiled:

Sys.sleep(1)
1 + 1
## [1] 2
plot(cars)

plot of chunk test-cache-b

cache=2 is similar to cache=1, and the only difference is that the plots will not be redrawn, in which case you need to make sure you did not delete the figure files manually:

Sys.sleep(1)
1 + 1
## [1] 2
plot(cars)

plot of chunk test-cache-c

cache=TRUE or cache=3 means to cache the text output of a chunk; none of the output hooks will be called when the document is recompiled, and the plots will not be redrawn, either:

Sys.sleep(1)
1 + 1
## [1] 2
plot(cars)

plot of chunk test-cache-d

Below is a test case for #588:

pairs(matrix(rnorm(100), ncol = 100), labels = 1:100, pch = ".")

plot of chunk test-cache-e

Another test case, with more plots:

Sys.sleep(5)
plot(1:10)
abline(0, 1)

plot of chunk test-cache-f

plot(2:11)

plot of chunk test-cache-f



Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on Aug. 21, 2025, 5:27 p.m.