我已成功使用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
的使用有关,但如果我删除它,没有输出,则不打印任何图。我能做些什么来解决这个问题?
提前致谢
答案 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。