使用knitr缓存大型数据表
我正在尝试缓存一个big data.table,然后将其绘制出来,代码如下:使用knitr缓存大型数据表,r,caching,plot,r-markdown,knitr,R,Caching,Plot,R Markdown,Knitr,我正在尝试缓存一个big data.table,然后将其绘制出来,代码如下: {r gen-data, tidy=TRUE, warning=FALSE, tidy.opts=list(width.cutoff=60), cache = TRUE, cache.lazy=FALSE} DT = fread("reference.txt.gz", header = FALSE) vc = c("chromosome_1", "chromosome_2", "chromosome_3", "chr
{r gen-data, tidy=TRUE, warning=FALSE, tidy.opts=list(width.cutoff=60), cache = TRUE, cache.lazy=FALSE}
DT = fread("reference.txt.gz", header = FALSE)
vc = c("chromosome_1", "chromosome_2", "chromosome_3", "chromosome_4", "chromosome_5", "chromosome_6")
colnames(DT) = c("chrom", "position", "score", "corrected base", "score of the corrected base")
DT=setDT(DT, key = "chrom")[J(vc), nomatch = 0]
所以我想的是,第一个块将数据读入data.table,然后应用相关选择,最后缓存一个DT对象
但是,无论发生什么情况,每次都会对第一个块进行评估。因此,我一定是做错了什么,但我看不出是什么
谢谢你的帮助
编辑:
添加一些,这里是reference.txt示例(是的,这是正常的,它只有3个列条目,有些行最多可以有5个)
你能发布一个小的可复制的例子吗?我们没有
“reference.txt.gz”
,因此无法运行您的代码。哦,是的,对不起,当然,已经完成了。非常感谢。
{r, cache=TRUE, tidy=TRUE, warning=FALSE, tidy.opts=list(width.cutoff=60), dependson='gen-data'}
plot = ggplot(data = DT) + geom_line(aes(x = position, y = score, group = 1), stat = "summary_bin", fun.y = "mean", binwidth = 100000, color = ghibli_palette("MononokeMedium")[2])
ttle = paste0("coverage of the 6 longest scaffolds of Shasta + instagraal assembly")
plot = plot + labs(
title = ttle) + theme(plot.title = element_markdown(lineheight = 1.5, size = 12), legend.text = element_markdown(size = 14))
plot = plot + theme(axis.title = element_markdown(size = 12)) + theme(axis.text.x = element_text(size=5)) + theme(axis.text.y = element_text(size=3))
plot = plot + theme(legend.title = element_markdown(size = 12))
p = plot + facet_wrap(~chrom, scales = "free_x") +xlab( "position") + ylab("mean score per 100 Kb windows")
v = ggplotly(p) %>%
layout(
xaxis = list(automargin=TRUE),
yaxis = list(automargin=TRUE)
)
v
chromosome_1 1 91
chromosome_1 2 91
chromosome_1 3 91
chromosome_1 4 91
chromosome_1 5 91
chromosome_1 6 91
chromosome_1 7 91
chromosome_1 8 91
chromosome_1 9 91
chromosome_1 10 91