简体   繁体   English

R markdown Page Break from Function

[英]R markdown Page Breaks from Function

I am trying to break to a new page from a R markdown document that is calling a function to produce a set of graphics for each set of data (400+ pages in some cases). 我试图从一个R markdown文档中断到一个新页面,该文档调用一个函数来为每组数据生成一组图形(在某些情况下为400多页)。 I am using LaTeX. 我正在使用LaTeX。

Any ideas? 有任何想法吗? Here is a simple example that demonstrates some my challenge though it doesn't use a function to produce the output. 这是一个简单的例子,它演示了我的一些挑战,虽然它没有使用函数来产生输出。

---
title: "Test Page Break"
output: pdf_document
---


```{r}
summary(cars)
cat("\\pagebreak")
print(cars)
```

Update #1: 更新#1:
My example didn't demostrate the use of a function within the code chunk. 我的例子没有说明在代码块中使用函数。 Here is a better example. 这是一个更好的例子。

---
title: "Test Page Break"
output: pdf_document
---


```{r}
pr_w_pagebreak <- function() {
print(summary(cars))
cat("\\pagebreak")
print(cars)
}
pr_w_pagebreak()
```

The trouble you'll have with your chunks is that you want some results to appear as 'markup' and some to appear 'asis'. 您对块的麻烦在于,您希望某些结果显示为“标记”,而某些结果显示为“asis”。 If you want to get the page break with the single block as you have it, you will need to do: 如果您希望使用单个块获取分页符,则需要执行以下操作:

```{r, echo=-2}
summary(cars)
knitr::asis_output("\\pagebreak")
print(cars)
```

Otherwise, you'll have to do 否则,你必须这样做

```{r}
summary(cars)
```

\pagebreak

```{r}
print(cars)
```

And as Floo0 points out, you can get LaTeX code from the R chunks if you use results = 'asis' , but you have to be careful because the following will not give you what you want. 正如Floo0指出的那样,如果你使用results = 'asis' ,你可以从R块中获取LaTeX代码,但你必须要小心,因为以下内容不会给你你想要的东西。

```{r, results='asis'}
summary(cars)
cat("\\pagebreak")
print(cars)
````

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM