How can I knit a .Rnw-file into latex, with plots as tikzpicture environments? (error: formal argument matched by multiple actual arguments)

How can I knit a .Rnw-file into latex, with plots as tikzpicture environments? (error: formal argument matched by multiple actual arguments)

我正在尝试将 .Rnw 文档转换为 Latex(以包含在另一个 .tex 文档中)。所有图都是使用 tikz 设备生成的,但每个图都是一个独立的文档。我的目标是让它们处于 tikzpicture 环境中。

解决方案尝试

根据knitr documentation on plots, it should be possible to pass standAlone=FALSE via the dev.args-list. This produces the error message formal argument "standAlone" matched by multiple actual arguments. Knitr issue #514描述了同样的错误信息,但是他们的解决方案在这里不起作用。

要复制,运行 knitr::knit("mwe.Rnw") 在以下文件上:

\section*{MWE}
<<echo=FALSE,dev="tikz",dev.args=list(standAlone=FALSE)>>=
plot(x=1:10)
@

错误信息:

Quitting from lines 3-4 (mwe.Rnw) 
Error in tikzDevice::tikz(..., packages = c("\n\nonstopmode\n", packages,  : 
  formal argument "standAlone" matched by multiple actual arguments

根据 tikzDevice documentationstandAlone=FALSE 应该是默认值,不知道为什么这在这里不适用。

非常感谢任何帮助。 seemingly related, but less specific, question 已发布但没有回复。

设置

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.2

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

knitr_1.27
tikzDevice_0.12.3

参数standAlone由块选项external控制,所以你需要的是:

<<dev="tikz", external=FALSE>>=