Brief answer:
Apply these options: prefix=T
then eval=F
Long answer:
Make the figures as separate files, then disable the chunk evaluation and include PDF of the figure.
prefix=T
: filenames of figures are generated with common prefix (by default the name of the source file).
eval=F
: The code chunk is not evaluated, and hence no text or graphical output created.
Play with the options in this MWE:
\documentclass{article}
\begin{document}
The A chunk
<<a,echo=T,eval=T,results=hide>>=
a <-2+3
a
@
The B chunk
<<b,echo=T,eval=T,fig=T,prefix=T,results=verbatim>>=
b <- a+3
b
cars <- c(1, 3, 6, 4, 9)
plot(cars)
@
\end{document}
Other options of some interest could be results=hide
(output is suppressed, but code is executed).
However, even if you can disable the evaluation or the ouput of some chunks, may be this cannot help significantly with some large documents, as the result of a chunk often depend of earlier chunks, that is a pain switch on and off to avoid the rendering of some figures.
To test some chunk at the beginning or middle of the document and skipping all subsequent chunks, the faster is simply add a \end{document}
after it.
`
The likely cause of this problem is simply that your source file is not encoded in UTF-8 but R is producing UTF-8 output. The first thing you need to do is make sure that your source file is encoded using UTF-8.
Check the General Preferences in R-Studio to see what the default text encoding is. It's best if it's UTF-8, and I think that's the default for R-Studio. If it's not, you can change it to UTF-8.
If your original file was already UTF-8 encoded then you just need to fix the LaTeX source (as described below). If it was not, then you need to resave the file using Save with Encoding from the File menu.
Assuming your file is now encoded correctly, you need to change the source. There are two ways to do this: you can add the inputenc
package to your source and use pdfLateX as your engine or you can use XeLaTeX as your engine. The engine choice can be set in the Sweave preferences of R-Studio.
Using pdflatex
Add the following to your preamble:
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
Using xelatex
Add the following to your preamble: (do not use inputenc
).
\usepackage{fontspec}
Best Answer
(Upgraded from a comment.)
Just use
library("knitr"); knit("file.Rnw")
in the console (where"file.Rnw"
is the name of your Sweave file, of course). This will produce"file.tex"
in the working directory.