【发布时间】:2019-09-26 15:16:51
【问题描述】:
我很了解 R,但我从 Sweave 开始。
我在 Rstudio 下从几个脚本生成报告:
- graphic.R,它定义了一个用 ggplot2 创建的名为 graph_1 的图形。我想在报告中显示它。
- script.Rnw 包含 Latex 和 Sweave 代码。我调用 graph_1 来显示我的图形。
- main.R 脚本,用于执行 .Rnw 代码并因此生成报告。
在graphic.R中
library(ggplot2)
graph_1 <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(aes(color=Species, shape=Species))
在 script.Rnw 中
\documentclass[french,12pt]{article}
\begin{document}
... no important...
\begin{figure}[h]
\begin{center}
<< fig=TRUE, echo=FALSE, height = 2.5>>=
graph_1
@
\caption{caption figure 1}
\label{graph_1}
\end{center}
\end{figure}
\end{document}
在 main.R 中
Sweave("script.Rnw", encoding="UTF-8")
tools:::texi2dvi(file="script.tex"), pdf=TRUE)
一切正常:我的报告 (.pdf) 在文件夹中生成。但我也有一个文件:“script-001.pdf”,其中包含我添加到同一文件夹中的图形。
我只想要最终报告而不想要中间文件:所以不要文件'script-001.pdf'。 有人知道这是否可能吗?
谢谢,
【问题讨论】: