I also use sweave (a few months) and latex (20 years). With a reasonably fast machine, the optimal scheme is simply to rebuild often. I use "make" (on a unix-like machine) so that only the chapters whose Rnw file has changed get rebuilt into tex files. That saves a lot of sweave time.
Alternatively, you can edit the .tex file and work away at errors, and put your results back into the .Rnw file when you're ready. But that's error-prone.
If you run sweave-latex often, and fix errors as soon as you see them, then you won't make so many errors.
The other advice is to use a decent editor (e.g. emacs) that does a lot of the work for you, e.g. finishing off parenthetic blocks, begin/end environments and so forth. That prevents 2/3 of the errors you're likely to make.
there are two ways to do what you seek. one is using sweave, the other is using an R package called brew which overcomes sweave's limitations of looping over a global variable. i am providing both code chunks.
The Sweave Code Chunk
\begin{document}
<<echo = F, results = tex>>=
figdir = paste(getwd(), 'fig', sep = '/')
fignames = read.csv('fignames.csv');
for (i in seq_along(fignames)) {
filename = file.path(figdir, i)
cat("\\pagebreak");
cat("\\section{", i, "}", sep = "");
cat("\\begin{figure}[htbp]");
cat("\\caption*{MyCaption", i, "}", sep = "");
cat("\\includegraphics[width = 0.5\\textwidth]{", filename, "}", sep = "");
cat("\\end{figure}");
}
@
\end{document}
The Brew Code Chunk
\begin{document}
<% figdir = paste(getwd(), 'fig', sep = '/') %>
<% fignames = read.csv('fignames.csv');
<% for (i in seq_along(fignames)) { -%>
\pagebreak
<% filename = file.path(figdir, i) %>
<%= cat("\section{", i, "}", sep = "") %>
\begin{figure}[htbp]
\caption*{MyCaption}
<%= cat("\\includegraphics[width = 0.5\\textwidth]{filename}")
\end{figure}
<% } -%>
\end{document}
you can check out the link to brew on how to use it from R
EDIT: this would produce a single file with all the output.
Best Answer
I would use
siunitx
for typesetting the number with the percent sign, which will take care of the correct spacing, and do the conversion to a percentage and the rounding within the\Sexpr
: