3

For example if my data frame was:

 exampledf <- data.frame(column = c("exampletext1", "exampletext2",  "exmapletext3"))

I would like the first page to have "exampletext1", the second page to have "exampletext2", etc.

\pagebreak works:

```{r, echo=FALSE}; exampledf[1,]```
   \pagebreak  
```{r, echo=FALSE} exampledf[2,]```

But my data frame is too large to make it practical.

I really need to loop through all my values:

for(i in 1:NROW(exampledf)) {
  single <- exampledf[i]
  strwrap(single, 70))
}

It's a weird question I realize.

eipi10
  • 91,525
  • 24
  • 209
  • 285
RyGuy
  • 305
  • 4
  • 12

1 Answers1

5

You can put \\newpage inside the cat function to add a page break after each iteration of the loop. The chunk also needs to have the parameter results="asis". For example, does something like this work for you:

```{r echo=FALSE, results="asis", warning=FALSE}
library(xtable)

exampledf <- data.frame(column = c("exampletext1", "exampletext2",  "exmapletext3"))

for (i in 1:nrow(exampledf)) {

  # Just added this as another way of displaying a row of data
  print(xtable(exampledf[i, , drop=FALSE]), comment=FALSE)

  print(strwrap(exampledf[i,], 70))

  cat("\n\\newpage\n")

}

```
eipi10
  • 91,525
  • 24
  • 209
  • 285
  • Thank you. I notice it doesn't work for Word docs. Is there different syntax for that? – RyGuy Apr 16 '16 at 03:26
  • 1
    `\newpage` is latex syntax. I'm not sure how to code a page break for a Word doc. – eipi10 Apr 16 '16 at 03:58
  • For the record, if anyone else stumbles upon this - It is possible program a page break into word, although not straightforward: http://stackoverflow.com/questions/24672111/how-to-add-a-page-break-in-word-document-generated-by-rstudio-markdown. Alternatively, you could simply insert flag text, i.e. "PAGE BREAK" into your document, and then replace it with a page break using replace all in word("^m") – RyGuy Apr 17 '16 at 02:29