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.

1 Answer 1

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")

}

```
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I notice it doesn't work for Word docs. Is there different syntax for that?
\newpage is latex syntax. I'm not sure how to code a page break for a Word doc.
For the record, if anyone else stumbles upon this - It is possible program a page break into word, although not straightforward: stackoverflow.com/questions/24672111/…. 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")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.