gpt4 book ai didi

r - 与新的 .Rnw 文件共享旧的 knitr 缓存

转载 作者:行者123 更新时间:2023-12-05 01:14:43 25 4
gpt4 key购买 nike

我正在编写两个报告(例如 example1.Rnw 和 example2.Rnw),其中第一个包含缓存 block ,我希望能够在第二个文档中访问和使用。

假设example1.Rnw是

\documentclass[a4paper, 11pt]{article}
\begin{document}
<<simpleExample, cache=TRUE>>=
z<-1+1
@
\end{document}

然后我想 example2.Rnw 会是这样的

\documentclass[a4paper, 11pt]{article}
\begin{document}
<<setup>>=
opts_chunk$set(cache.path = "~/DirectoryOfExample1/cache")
@
<<simplePrint, dependson = 'simpleExample'>>=
print(z)
@
\end{document}

这似乎与这个问题相似 How to cache knitr chunks across two (or more) files?除了我没有使用外部化。是否可以通过这种方式在新文档中重新使用旧缓存,如果可以,如何?

最佳答案

可以重用缓存,但恕我直言,您必须在 example2.Rnw 文件中复制 simpleExample block 。它必须与 example1.Rnw 中的完全相同(没有不同的空格,没有不同的选项,...)。

例子2.Rnw:

\documentclass[a4paper, 11pt]{article}
\begin{document}
<<setup>>=
opts_chunk$set(cache.path = "~/DirectoryOfExample1/cache")
@
<<simpleExample, cache=TRUE>>=
z<-1+1
@
<<simplePrint, dependson = 'simpleExample'>>=
print(z)
@
\end{document}

关于r - 与新的 .Rnw 文件共享旧的 knitr 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18576110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com