14

My question is linked to this one. I wish to include my appendix after my references so I am using the after_body tag in my yaml, however I need to be able to knit my appendix.Rmd file. I have tried the following:

after_body: "`r knitr::knit('appendix.Rmd')`"

however this attempts to knit the appendix.Rmd file before the actual report and therefore fails as it does not have the required libraries or objects in memory.

zx8754
  • 52,746
  • 12
  • 114
  • 209
nathaneastwood
  • 3,664
  • 24
  • 41
  • One work-around would be to manually generate the references section using something like the `bibliography()` function from [knitcitations](https://github.com/cboettig/knitcitations). – Keith Hughitt Jan 08 '17 at 14:46
  • If appendix.Rmd is reliant on libraries and objects generated by the .Rmd file you want to append it to, you will always have dependency issues. When you knit an .Rmd file it is run in its own, insulated environment (ensures reproducibility). Thus any libraries attached or objects generated when knitting a document will not be available to another .Rmd. – Peter K Jan 09 '17 at 05:13
  • Yeah I know that. But it must be possible to run it afterwards surely? – nathaneastwood Jan 09 '17 at 08:43

1 Answers1

27

In order to have appendices after the references, you simply include a div with id="refs" which tells pandoc where to include the references section. For example:

```{r, child = "08_discussion.Rmd"}
```

# References

<div id="refs"></div>

```{r, child = "09_appendix.Rmd"}
```

Credit: https://twitter.com/tjmahr/status/763435602935095296

nathaneastwood
  • 3,664
  • 24
  • 41