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

标签 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 有关,但是如果我删除它,则不会输出,不会打印任何图。我能做些什么来解决这个问题?

提前致谢

最佳答案

您可以在 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/

相关文章:

Stargazer Rmarkdown : LaTeX Error if align is set to TRUE

R:绘图:as.double(x) 中的错误:无法将类型 'S4' 强制转换为类型 'double' 的向量

r - 如果某列值在某个范围之间,则获取对应的值

R Markdown XTable 在表输出之前生成 ##

r - 如何获取 knitr .Rnw 文档中使用的软件包列表?

以 101% 的宽度和高度插入到 Word 中的 RMarkdown 图

r - 有没有一种简单的方法可以使用 Windows 10 在 R Markdown 上运行 bash 脚本?

r - 在 archlinux 中安装 R 的插入符号包的问题

r - 匹配单词串并返回不匹配的单词

r - 对于这个混合效果模型,什么是最好的 "formula"