【问题标题】:knit_child in a Rmd file is printing unwanted outputRmd 文件中的 knit_child 正在打印不需要的输出
【发布时间】:2013-09-20 18:22:37
【问题描述】:

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

提前致谢

【问题讨论】:

    标签: r knitr


    【解决方案1】:

    您可以在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')`
    

    【讨论】:

    • 感谢您的快速回答,不幸的是这不起作用...... otput 是一样的。还有其他想法吗?
    【解决方案2】:

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

    请参阅https://github.com/yihui/knitr/issues/741 了解相关主题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-27
      • 2011-12-19
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      相关资源
      最近更新 更多