Rmd文件中的knit_child正在打印不需要的输出

时间:2013-09-20 18:22:38

标签: r knitr

我已成功使用knit_child生成pdf文件,遵循http://yihui.name/knitr/demo/child/的代码,但当我尝试在.Rmd文件中使用该示例时:

```{r, results='asis', echo=FALSE, message=FALSE}
out = NULL
for (p in c("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10")) {
  out = c(out, knit_child('quick_variable.Rmd'))
  cat(out)
}
```

(我修改了原始代码,用于Rmd)。

我有两个问题,第一个:

|
| | 0% |
|... | 5% ordinary text without R code

|
|....... | 11% label: unnamed-chunk-4 (with options) List of 1 $ echo: logi FALSE

|
|.......... | 16% ordinary text without R code

|
|.............. | 21% label: unnamed-chunk-5 (with options) List of 2 $ echo : logi FALSE $ results: chr "asis"
.... 
(the output follows)

显然所有这些输出都是不需要的。我相信这个问题与上面代码中cat的使用有关,但如果我删除它,没有输出,则不打印任何图。我能做些什么来解决这个问题?

提前致谢

2 个答案:

答案 0 :(得分:8)

您可以在out中收集结果,然后在内联R表达式中将其写入输出,例如

```{r include=FALSE}
out = NULL
for (p in c("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10")) {
  out = c(out, knit_child('quick_variable.Rmd'))
}
```
`r paste(out, collapse='\n')`

答案 1 :(得分:0)

注意,我相信现在应该使用可以在 quiet = TRUE

中调用的 knitr::knit_child() 参数来解决这个问题

有关相关主题,请参阅 https://github.com/yihui/knitr/issues/741