我已成功使用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
有关,但是如果我删除它,则不会输出,不会打印任何图。我能做些什么来解决这个问题?
提前致谢
最佳答案
您可以在 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')`
关于r - Rmd 文件中的 knit_child 正在打印不需要的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18923392/