r语言 - 使用 rmarkdown (knitr) 引用主文件



>我有一个包含子文件的父文件,我想编译父文件,当我按 Cmd+shift+k 时(我正在使用 rstudio)。我知道在乳胶中,您可以通过在子文件的顶部编写一行代码来引用主文件。我想知道你是否可以用 rmarkdown 做类似的事情?

在R Markdown中,它的工作原理是这样的:

---
title: "parent"
output: pdf_document
---
This is the title page
```{r child='child1.Rmd'}
```
```{r child='child2.Rmd'}
```

在此示例中,子.Rmd文件位于同一文件夹中。

无需在子.Rmd 中指定 YAML 标头

knitr/demo/child/页面概述了如何执行此操作。

如果信息量不够,您可以查看论文模板存储库的自述文件的knitr部分。

最后,您可以在 https://github.com/stevenpollack/masters_thesis/blob/master/masters_thesis.Rnw 中看到父子模型的实际应用。该链接的精简版本将是:

documentclass[masters]{ucbthesis}
begin{document}
<<abstract, child='abstract.Rnw'>>=
@
<<introduction, child='introduction.Rnw'>>=
@
<<adaboostToBoost, child='boosting_methodology.Rnw'>>=
@
<<boostrImplementation, child='boostr_implementation.Rnw'>>=
@
<<discussion, child='summary_and_future_work.Rnw'>>=
@
end{document}

最新更新