I know R well but I start in Sweave.
I produce a report under Rstudio from several scripts:
- graphic.R which defined a graphic created with ggplot2 called graph_1. I want to display it in the report.
- script.Rnw containing Latex and Sweave code. I call graph_1 to display my graphic.
- main.R script that executes the .Rnw code and therefore produces the report.
In graphic.R
library(ggplot2)
graph_1 <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(aes(color=Species, shape=Species))
In 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}
In main.R
Sweave("script.Rnw", encoding="UTF-8")
tools:::texi2dvi(file="script.tex"), pdf=TRUE)
Everything is OK : my report (.pdf) is generated in the folder. But I also have a file : 'script-001.pdf' containing my graphic which is added in the same folder.
I would like only the final report and not the intermediate file : so not the file 'script-001.pdf'. Somebody know if it is possible ?
Thank you,