9

我已成功用于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上面代码中的使用有关,但是如果我删除它,就没有输出,也没有打印图。我能做些什么来解决这个问题?

提前致谢

4

2 回答 2

9

您可以在 中收集结果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')`
于 2013-09-20T20:08:42.043 回答
0

注意,我相信现在应该用quiet = TRUE可以调用的参数来解决这个问题knitr::knit_child()

相关线程见https://github.com/yihui/knitr/issues/741

于 2021-05-18T22:12:13.200 回答