r - Inserting a page break within a code chunk in rmarkdown (converting to pdf) -


i using rmarkdown, pandoc , knitr create pdf including chunks of r code. within code chunk have loop prints number of graphs , statistical output.

i insert page break loop (to appear in pdf output). page break occur after each graph printed, ensure each graph printed on 1 page , statistical output on next.

i have been unable find way of including page break in r code chunk. have tried cat("\\newpage") , cat("\\pagebreak") in hopes recognized pandoc no avail (it printed verbatim in final pdf).

suggestions appreciated. here code have far:

```{r, echo =false, message=false, warning=false, comment=na, results='asis'} library("markdown")  library("rmarkdown")  library("knitr") library("ggplot2") (v in values){  # read in file testr <- read.csv(file.path, header=t)  print(ggplot(testr, aes(x=time, y=value, color=batch)) + geom_point(size = 3) + xlab ("timepoint") + ylab (v) + scale_x_continuous(breaks=seq(0, 60, by=6)) + ggtitle(paste("scatterplot of batches ", v, sep=""))) ggsave(paste(timestamp, "__",         "scatterplot of batches ", v, ".jpeg", sep = ""))   cat("\\pagebreak") writelines(v) writelines("\n") writelines("\n test homogenity of slopes \n") av1 <- aov(value~time*batch, data=testr) print(summary(av1)) } ``` 

see below reduced , reproducible example. answer , general remarks:

  • to dynamically create new pages or sections in markdown document use results='asis' in chunk options.
  • you have add linebreak (\n) after \\pagebreak or else "valueforv" pasted directly after "\linebreak", results in undefined control sequence error.
  • make sure \newpage , \pagebreak in separate line using linebreaks \n before.
  • escape \newpage , \pagebreak (i.e., \\newpage, \\pagebreak).

    --- title: "test" output: pdf_document ---  ```{r, echo=false, results='asis'} (i in 1:3) {   print(ggplot2::qplot(i, i+1))   cat("\n\n\\pagebreak\n")   writelines("valueforv") } ``` 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -