Rmd文件中的knit_child打印不需要的输出 [英] knit_child in a Rmd file is printing unwanted output

查看:249
本文介绍了Rmd文件中的knit_child打印不需要的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I had succesfully used knit_child for generating pdf files, following the code of http://yihui.name/knitr/demo/child/, but when I try to use that example in a .Rmd file:

```{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中的工作).

(I modify the original code, for work in Rmd).

我有两个问题,第一个:

I have two problems, the first one:

|
| | 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的使用有关,但是如果我删除它,则不会输出任何内容,也不会打印任何图.我该怎么办?

Obviously all this output is unwanted. I believe that this problem is related to the use of cat in the code above, but if I remove that, no output, no plots is printed. What can I do for solving this?

预先感谢

推荐答案

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

You can collect the results in out, and write it to the output later in an inline R expression, e.g.

```{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')`

这篇关于Rmd文件中的knit_child打印不需要的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆