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
:=
assignement then it acts as though that chunk has not been run, and later chunks do not see the affect of the :=
.
Any idea why this is? How does knitr
detect objects have updated, and what is data.table
doing that confuses it?
It appears you can work around this by doing DT = DT[, LHS:=RHS]
.
Example:
```{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}
DT[, c:=5]
```
Then we display that in a non-cached block
```{r, cache=FALSE}
DT
```
The first time you run this, the above will show a `c` column,
from the second time onwards it will not.
Output on second run