Davor Josipovic
Davor Josipovic

Reputation: 5504

Working on separate bookchapters with R Markdown

Suppose I am writing a document with the following layout:

Ch1
  Ch1.1
Ch2
...

where Ch stands for some chapter in the document.

Each Ch is a separate file, for example Ch1.1.rmd. There is one file main.rmd which has the following structure:

```{r child='Ch1.rmd'}
```
```{r child='Ch1.1.rmd'}
```
```{r child='Ch2.rmd'}
```
...

If I compile main.rmd I get the whole document, which works great.

But I work on separate chapters at a time, and don't want to compile the whole document each time to see the result. The problem is that there are dependencies. Ch1.1.rmd uses functions defined in Ch1.rmd, so it doesn't compile on itself.

What are efficient ways to work on _separate_ chapters with dependencies to others while keeping the document (and possibly dependency) structure _in one place_?

Note: putting functions in a separate file, and loading it prior to compilation of each chapter is not an option since all functions/variables are inline with text.

Upvotes: 1

Views: 301

Answers (1)

Pascal
Pascal

Reputation: 151

You might use the caching options in knitr and the dependson argument.

Your example would be:

{r Ch1, child='Ch1.rmd', cache=TRUE} {r child='Ch1.1.rmd', dependson='Ch1'} {r child='Ch2.rmd'}

Upvotes: 2

Related Questions