Caching Code Chunks

To compile your document faster, specified code chunks can be cached. This allows compute intensive chunks to be saved and the output used later without being rerun. To cache a chunk in knitr, simply use the cache=TRUE option as shown here:

alt text

The knitr package is elegantly designed to only evaluate cached chunks when necessary. It creates a unique MD5 digest of each chunk to track when changes are present. When cache=TRUE, the chunk will only be evaluated in the following scenarios:

The cached results and output are stored in a cache/ directory relative to the current working directory. This directory can be customized with the cache.path optoin. The full details of each option are copied below:

For additional information and examples, see the cache section of the knitr documentation.

Return to Using Markdown with RStudio