0

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?

Stephen K
  • 697
  • 9
  • 26
  • You might pre-process an `Rmd` file, create multiple `Rmd` file programmatically to be joined,and I love to promote this related feature of [pander](http://rapporter.github.io/pander/#brew-to-pandoc) as well. – daroczig Aug 05 '15 at 03:44

1 Answers1

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:enter image description here

CL.
  • 14,577
  • 5
  • 46
  • 73