ABSTRACT

Cache is not a new idea — both the packages cacheSweave and weaver have implemented it based on Sweave, with the former using filehash and the latter using *. The cacheSweave vignette has clearly explained the concept of lazy-loading. The path of cache files is determined by the chunk option cache.path; by default all cache files are created under a directory cache/ relative to the current working directory. The cache is invalidated and purged on any changes to the code chunk, including both the R code and chunk options; this means old cache files of this chunk are removed and replaced by new cache files. In any case, dependency on uncached chunks is meaningless to knitr, because knitr only checks changes for cached chunks; knitr will give a warning when it sees dependency on uncached chunks. Usually the cache database is automatically loaded for a cached chunk, and we can actually load it manually.