Why do I want to do this? To break up a giant document into logical files.

I've used @hadley 's bookdown package to build latex from .Rmd but this seems like overkill for this particular task. Is there a simple solution using knitr/pandoc/linux command line I'm missing? Thanks.

Why not just write natively in LaTeX? Seems like all the tools you need for this are built into LaTeX and the knitting process runs your document through a TeX engine anyway.
– ThomasSep 13 '14 at 16:30

10

Yes I like latex and need to get into embedding code into it so that's a good plan B. Working on an R solution with read/writeLines function ATM because I believe Markdown is the user-friendly future! arxiv.org/abs/1402.1894 I.e. it's a philosophical decision: be the change you want to see in the world.
– RobinLovelaceSep 13 '14 at 16:39

2

Also, writing as markdown reduces the barrier to entry to contributing. Eventually it will be LaTeX, but for the time being markdown is sufficient.
– RobinLovelaceSep 13 '14 at 17:46

4

hadley's bookdown is now being developed by @yihui and has had a lot of further work and useful documentation: rstudio.github.io/bookdown
– BenJan 5 '16 at 12:20

3 Answers
3

August, 2018 update: This answer was written before the advent of bookdown, which is a more powerful approach to writing Rmarkdown based books. Check out the minimal bookdown example in @Mikey-Harper's answer!

When I want to break a large report into separate Rmd, I usually create a parent Rmd and include the chapters as children. This approach is easy for new users to understand, and if you include a table of contents (toc), it is easy to navigate between chapters.

I'd recommend that people use the bookdown package for creating reports from multiple R Markdown files. It adds a lot of useful features like cross-referencing which are very useful for longer documents.

Adapting the example from @Eric, here is a minimal example of the bookdown setup. The main detail is that the main file has to be called index.Rmd , and must include the additional YAML line site: bookdown::bookdown_site:

is it possible to render nested Rmd files this way? how? I would like to have single Rmd for each element in a chapter.
– jangoreckiAug 23 '18 at 13:16

bookdown generally recommends each file contains one chapter. However, it should be possible to split into separate files if desired. The easiest way would be to provide each file with a numeric index such as 1-1, 1-2, 1-3 etc.
– Michael HarperAug 23 '18 at 13:23

I was trying to add appendix at the end which shows code for both document. How can i achieve ?
– Naveen GabrielFeb 5 at 20:00

This seems like a distinct different question. You may want to open another question and provide a complete example which I will try my best to answer :)
– Michael HarperFeb 5 at 20:17