Rac*_*el 17 pdf r pandoc knitr r-markdown
我正在使用rmarkdown,pandoc和knitr来创建包含r代码块的pdf.在一个代码块中,我有一个for循环,它打印了许多图形和一些统计输出.
我想在循环中插入一个分页符(出现在pdf输出中).打印每个图形后会发生此分页,以确保每个图形打印在一个页面上,统计输出打印在下一个页面上.
我一直无法找到在我的r代码块中包含分页符的方法.我已经尝试cat("\\newpage")并cat("\\pagebreak")希望它能被pandoc识别但无济于事(它只是在最终的pdf中逐字打印).
建议表示赞赏.这是我到目前为止的代码:
```{r, echo =FALSE, message=FALSE, warning=FALSE, comment=NA, results='asis'}
library("markdown")
library("rmarkdown")
library("knitr")
library("ggplot2")
for (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 for ", v, sep="")))
ggsave(paste(timestamp, "__",
"Scatterplot of Batches for ", v, ".jpeg", sep = ""))
cat("\\pagebreak")
writeLines(v)
writeLines("\n")
writeLines("\n Test for homogenity of slopes \n")
av1 <- aov(Value~Time*Batch, data=testR)
print(summary(av1))
}
```
Run Code Online (Sandbox Code Playgroud)
Chr*_*oph 28
请参阅下面的简化和可重复的示例.答案和一些一般性评论:
results='asis'块选项.\n),\\pagebreak否则"ValueForV"将在之后直接粘贴"\linebreak",这会导致Undefined control sequence错误.\newpage并且\pagebreak在单独的行中\n.逃避\newpage和\pagebreak(即\\newpage,\\pagebreak).
---
title: "test"
output: pdf_document
---
```{r, echo=FALSE, results='asis'}
for (i in 1:3) {
print(ggplot2::qplot(i, i+1))
cat("\n\n\\pagebreak\n")
writeLines("ValueForV")
}
```
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
18868 次 |
| 最近记录: |