When working in R Markdown, I typically add text outside of a chunk (e.g., figure/tables headings) but in this case I need to loop through 50+ variables to create a couple plots specific to each variable. Hence, I'm adding a few lines of text within the code chunk so that it is included with each set of plots. Ideally, I'd also like to add a page break before moving on to the next variable as well. I'm knitting to Word (this is the format that has been requested of me).
I've tried adding spaces after each line, "/newline", "/n", without success (I've tried with one backslash and two, as I wasn't clear which to use for a Word doc). I could just edit the document manually but that kind of defeats the purpose! Any tips would be appreciated.
```{r create plots, echo=FALSE, fig.height=8, fig.width=8, results='asis'}
for (i in seq(1, nrow(variables))) {
x <- variables[i,]
x <- drop.levels(x)
var <- x$variables
# Add some text
cat("Variable: **", paste(var), "** (N = ", number obs, ")", sep="")
cat("\n")
cat("More Text")
cat("\n")
cat("Even more text")
# Create plots.....
# insert page break
cat("\pagebreak")
}
```