Reputation: 103
I try to shift from Sweave to knitr but I am stucked with a problem to use multiple plots in one chunk. Here an example: Let this .Rnw simple file (named Essai.Rnw). Of course only one plot is shown in the pdf:
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<fig=TRUE>>=
plot(1:10, exp(1:10))
plot(1:10, log(1:10))
@
\end{document}
I transform it to knitr format using:
library("knitr", lib.loc="/Library/Frameworks/R.framework/Versions/3.0/Resources/library")
Sweave2knitr("Essai.Rnw")
I edit the file to get this:
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<include=FALSE>>=
require(knitr)
opts_chunk$set(concordance=TRUE)
@
<<>>=
plot(1:10, exp(1:10))
plot(1:10, log(1:10))
@
\end{document}
In Rstudio global preference, I set Weave Rnw files using Knitr and when I produce pdf file using Compile pdf button in Rstudio, i get only one plot, not the 2 as I expected.
Here is my sessionInfo()
> sessionInfo()
R version 3.0.1 Patched (2013-06-10 r62935)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.2
loaded via a namespace (and not attached):
[1] digest_0.6.3 evaluate_0.4.3 formatR_0.7 stringr_0.6.2 tools_3.0.1
Upvotes: 2
Views: 759
Reputation: 5165
If I compile the following, I get two plots. Note the deletions I made. Your original code did not compile on my system.
\documentclass{article}
\begin{document}
<<include=FALSE>>=
opts_chunk$set(concordance=TRUE)
@
<<>>=
plot(1:10, exp(1:10))
plot(1:10, log(1:10))
@
\end{document}
Maybe read about the knitr option fig.keep=
about how your plots get integrated into the output.
Upvotes: 1
Reputation: 4380
Not sure this is the cause of your problem but if you weave it with knitr, I think you have to remove the \SweaveOpts{concordance=TRUE}
line.
Upvotes: 1