knitr模板和循环中的子文档

Sea*_*ean 9 markdown r knitr

在圣诞节之前,我之前曾在多个knitr文档中询问单一样式表.我现在知道我遗漏的关键搜索词是"子文档".

我创建了一个最小的降价示例,但我在创建的文档中获取了编织过程中的标题.我正在使用RStudio来处理它.我见过很多类似的问题,但没有一个答案可行.我已经尝试了各种组块的参数,到目前为止无济于事.

问题:如何摆脱最终针织文件中的标题?

# Master document

```{r master1, comment='', echo=FALSE, message=FALSE, warning=FALSE, results="asis", fig.width= 4., fig.height= 4, fig.cap= ""}
out = NULL
for (i in 1:3) {
  # lets create three different uniform data sets.
  v1 <- sort(rnorm(2))
  uvec <- runif(10, v1[[1]], v1[[2]])
  # now we want to 
  out <- c(out, knit_child('child.Rmd'))
}
cat(paste(out, collapse = '\n'))
```
Run Code Online (Sandbox Code Playgroud)

子文档包含:

## child document `r i`

Here is a summary of the dataset:
```{r echo=FALSE}
summary(uvec)
```
Run Code Online (Sandbox Code Playgroud)

不幸的是,我也得到一个讨厌的标题....

|
| | 0% |
|…………………. | 33% inline R code fragments

|
|……………………………………. | 67% label: unnamed-chunk-1

|
|………………………………………………………..| 100% ordinary text without R code

|
| | 0% |
|…………………. | 33% inline R code fragments

|
|……………………………………. | 67% label: unnamed-chunk-2

|
|………………………………………………………..| 100% ordinary text without R code

|
| | 0% |
|…………………. | 33% inline R code fragments

|
|……………………………………. | 67% label: unnamed-chunk-3

|
|………………………………………………………..| 100% ordinary text without R code
Run Code Online (Sandbox Code Playgroud)

Mat*_*bos 11

肖恩给出答案对我不起作用.对我有用的代码是:

# Master document

```{r echo=FALSE, include=FALSE}
library(knitr)

out = NULL
for (i in 1:3) {
  # lets create three different uniform data sets.
  v1 <- sort(rnorm(2))
  uvec <- runif(10, v1[[1]], v1[[2]])
  out <- c(out, knit_child('child.Rmd'))
}
```

```{r, echo=FALSE, results="asis"}
cat(paste(out, collapse = '\n'))
```
Run Code Online (Sandbox Code Playgroud)


Sea*_*ean 6

一个答案是使用knit_expand()而不是knit_child()以及knit(, quiet=TRUE)稍后 - 这是一个修改后的主文档.

# Master document
```{r master1, comment='', echo=FALSE, message=FALSE, warning=FALSE, results="asis", fig.width= 4., fig.height= 4, fig.cap= ""}
out = NULL
for (i in 1:3) {
  # lets create three different uniform data sets.
  v1 <- sort(rnorm(2))
  uvec <- runif(10, v1[[1]], v1[[2]])
  out <- c(out, knit_expand('child.Rmd'))
}
cat(knit(text=unlist(paste(out, collapse = '\n')), quiet=TRUE))
```
Run Code Online (Sandbox Code Playgroud)