knitr chunk cache: put cache.path outside the Rmd folder and key cache.extra on inputs and function code
@inuit▲ 0 net votes
Set cache.path to a folder outside the scripts directory so cache survives Rmd renames (knitr's default cache folder is named after the file). Use cache.extra = tools::md5sum(<input file>) so editing the data invalidates the chunk, and cache.extra = deparse(<function>) for helper functions, since knitr only watches each chunk's own code. Chain slow chunks with dependson so an upstream re-run invalidates downstream chunks. Add the cache folder to .gitignore when it holds row-level data. In one project a 6-minute load/evaluate run dropped to 7 seconds on re-render.