sourcing References in rmarkdown: workaround

2019-04-29 20:03发布

问题:

I am working with markdonw v2, the rmarkdown package. Throughout the .Rmd file, I create links to websites or images

[Link1][pathLink1]
![Image1][pathImage1]

then, at the end of the document I give the references

[pathLink1]:http://website.com/linkes/Link1.md 
![pathImage1]:./images_rmd/

There are other reports that talk about the same citation and use same images in different contexts. I would like to create a separate file containing all the links and path difinitions, so that I could simply source it at the end of each .Rmd file, like I would call in an R environment

source(/Rcode1.R)

Question: How do I "source" another file in .Rmd, so that the sourced code prints needed text strings into the .Rmd file?

This would offer some help with citations and scientific paper composition in HTML and PDF.

回答1:

http://yihui.name/knitr/demo/child/

```{r child, child = '~/path/to/child.Rmd'}
```

and similarly for .Rnw files:

<<child, child = '~/path/to/child.Rnw'>>=
@

And a full example: https://github.com/yihui/knitr-examples/blob/master/087-child-example.Rnw