循环中的knitr模板和子文档 [英] knitr templates and child documents in a loop
问题描述
在圣诞节之前,我之前曾问过跨多个编织文档的单个样式表.我现在知道我缺少的关键搜索词是子文档".
Before Christmas I previously asked single style sheet across multiple knitr documents. I now know that the key search term I was missing is "child document".
我创建了一个最小的markdown示例,但是我在创建的文档中得到了标题,这些标题是编织过程的一部分.我正在使用RStudio对其进行处理.我见过许多类似的问题,但是没有一个答案有效.到目前为止,我已经尝试了块参数的各种组合,但无济于事.
I have created a minimal markdown example but I am getting headers in the created document that are part of the knitting process. I am using RStudio to process it. I have seen many similar questions, but none of the answers work. I have tried various combinations of the chunk parameters and so far to no avail.
问题:如何摆脱最终编织文档的标题?
Question: How do I get rid of the header from the final knitted document?
# 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'))
```
子文档包含:
## child document `r i`
Here is a summary of the dataset:
```{r echo=FALSE}
summary(uvec)
```
不幸的是,我也得到了一个烦人的标题....
Unfortunately I also get an annoying header ....
|
| | 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
推荐答案
一个答案是使用knit_expand()
代替knit_child()并稍后使用knit(, quiet=TRUE)
-这是经过修订的主文档.
One answer is to use knit_expand()
instead of knit_child() and to knit(, quiet=TRUE)
later - here is a revised master document.
# 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))
```
这篇关于循环中的knitr模板和子文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!