这在精神上与this问题有关,但在机制上必须不同。
如果您尝试缓存包含data.table
:=
分配的knitr
块,那么它的行为就像该块尚未运行一样,并且以后的块看不到:=
的影响。
知道为什么会这样吗?knitr
是如何检测对象已经更新的,data.table
做了什么让它困惑的事情?
看起来你可以通过执行DT = DT[, LHS:=RHS]
来解决这个问题。
示例
```{r}
库(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.
第二次运行时的输出
https://stackoverflow.com/questions/15298359
复制相似问题