I have a data frame that has demographic information split into 16 groups. I basically need to iterate over these groups and create a PDF page for each group. I've tried using Rhtml but so far I can only get one page to generate. Is there a way to use templates or something?
            Asked
            
        
        
            Active
            
        
            Viewed 1,090 times
        
    1 Answers
0
            When you need PDF output, why don't you directly compile .Rnw to .pdf?
Here an example using the iris dataset. It prints the first few rows of each species on a new page:
\documentclass{article}
\begin{document}
<<results = "asis", echo = FALSE>>=
library(xtable)
newpage <- ""
invisible(lapply(unique(iris$Species), FUN = function(x) {
  cat(newpage)
  cat(sprintf("\\section{%s}", x))
  current <- head(subset(x = iris, subset = Species == x))
  print(xtable(current))
  newpage <<- "\\clearpage"
}))
@
\end{document}
I additionally used xtable to easily get a nicely formatted table. The output looks like this:
 
    
    
        CL.
        
- 14,577
- 5
- 46
- 73
