This is related in spirit to this question, but must be different in mechanism.
If you try to cache a knitr
chunk that contains a data.table
As indicated in the fourth comment under the answer by Josh O'Brien, I have added a new chunk option cache.vars
to handle this very special case. In the second cached chunk, we can specify cache.vars='DT'
so that knitr
will save a copy of DT
.
```{r}
library(data.table)
```
Data.Table Markdown
========================================================
Suppose we make a `data.table` in **R Markdown**
```{r, cache=TRUE}
DT = data.table(a = rnorm(10))
```
Then add a column using `:=`
```{r, cache=TRUE, cache.vars='DT'}
DT[, c:=5]
```
Then we display that in a non-cached block
```{r, cache=FALSE}
DT
```
The output is like this no matter how many times you compile the document: