【问题标题】:Including custom code block in a child document with bookdown在带有 bookdown 的子文档中包含自定义代码块
【发布时间】:2019-12-04 14:11:19
【问题描述】:

我正在尝试在 bookdown 的子 .Rmd 文档中包含自定义块,但是未编译包含在子文档中的自定义块。

我已按照此处https://bookdown.org/yihui/bookdown/custom-blocks.html 使用自定义块的说明进行操作

我加载了一个新的模板 bookdown 项目。如果我在章节中插入自定义块,例如01-intro.Rmd,则自定义块按预期工作。例如,包括

```{block, type="center"}
hello world
```

在构建手册上生成预期的 html 输出:

<div class="center">
<p>
hello
</p>
</div>

而且,预​​期的 tex 输出:

\begin{center}
hello
\end{center}

但是,如果自定义代码块包含在子文档中,则不会出现预期的输出。例如,我创建了一个新的 .Rmd 文件testchild.Rmd,其中包含:

```{block, type="center"}
hello world
```

并且,我在章节文档01-intro.Rmd中包含子文档如下:

 ```{r child="childfolder/testchild.Rmd", echo=FALSE}
 ```

现在,构建本书无法包含来自testchild.Rmd 的自定义块。具体来说,没有任何关于自定义块的内容被写入 html 或 latex。包含testchild.Rmd 中的任何其他文本和其他 knitr 块都没有问题。

非常感谢任何帮助。

【问题讨论】:

    标签: r r-markdown bookdown


    【解决方案1】:

    找到了一种解决方法,即将孩子打印到父母身上。在父文档01-intro.Rmd中包含以下内容,而不是上面包含子文档的方法似乎可以正确编译子文档中的自定义块。

     ```{r, echo=FALSE}
     knitr::asis_output(knitr::knit_child("childdoc/testchild.Rmd", quiet=TRUE))
     ```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多