Caching chunks in RStudio does not work

I've run your example (minus the last \), and I'm getting a cache. You'll need to provide some more details for us to look over. Try running a document with just this chunk:

```{r, cache=TRUE}
knitr::opts_current$get(c(
  "cache",
  "cache.path",
  "cache.rebuild",
  "dependson",
  "autodep"
))
```

You should see something like this:

## $cache
## [1] 3
## 
## $cache.path
## [1] "test_cache/html/"
## 
## $cache.rebuild
## [1] FALSE
## 
## $dependson
## NULL
## 
## $autodep
## [1] FALSE

If the cached objects have a large combined size in memory, it may be just taking that long to load them from disk. Here are two chunks to test if a cache is actually being created:

library(survival)
"survival" %in% loadedNamespaces()

The first time you knit the document, before there's a cache, the second chunk will give the result TRUE. Afterwards, if there is a cache, it'll show FALSE. This is because knitr doesn't capture loaded packages in cache.

1 Like