Caching

  • Normally, each render of a document starts from a completely clean slate. However, it can be painful if you have some computations that take a long time. The solution is cache: true in the YAML under execute.

  • You can also enable caching at the chunk level for caching the results of computation in a specific chunk using #| cache: true

  • The caching system must be used with care, because by default it is based on the code only, not its dependencies. You can avoid that problem with the dependson chunk option. Here you include the object that it calls out to run the chunk. dependson should contain a character vector of every chunk that the cached chunk depends on.

  • As your caching strategies get progressively more complicated, it’s a good idea to regularly clear out all your caches with knitr::clean_cache().