How to manage order of chapter knitting in bookdown?

Hi,

I'd like to use R Markdown and the bookdown package for keeping track of my project (which will contain many .Rmd's). I'm wondering is it possible to manage the order of knitting and order of merging separately? For example, I'll have the following files:

  • 01_intro.Rmd
  • 02_1_Series_of_experiment.Rmd
  • 02_2_Import_and_clean_data.Rmd
  • 02_3_Use_data_from_02_2.Rmd
  • 03_1...
  • 03_2...
  • etc.

In the file 02_2_Import_and_clean_data.Rmd I will include a code chunk to define how to import and clean the data, and how to save the clean data in the external file that can be used in the subsequent sections (e.g. 02_3_Use_data_from_02_2.Rmd). At the same time, while all this cleaning part is important, it does not add anything to the main story. Hence, I'd like to put it in Appendix of the report. So, my question is it possible to run Rmd files in the order as stated above, but arrange book chapters in the following order?

  • 01_intro.Rmd
  • 02_1_Series_of_experiment.Rmd
  • 02_3_Use_data_from_02_2.Rmd
  • 03_1...
  • 03_3...
  • etc.
  • Appendix
  • 02_2_Import_and_clean_data.Rmd
  • 03_2_Import_and_clean_data.Rmd
  • 04_2_Import_and_clean_data.Rmd

You can select the files to render using rmd_files key

However, you won't be able to control the order of knitting differently of the order shown in the book.

Using some knitr tricks, you could probably refactor your project and use child documents or R script to source for example. Using knitr options to hide / show chunk conditionnally, you could run in early doc but hide and then show in later docs.

This is not bookdown specific, you would do the same with long single document.
Several recipies in this book can be useful

It is not out of the box in bookdown, but I believe rmarkdown and knitr contains the tool to do it.

I let you try, and others share their experience;

@cderv ,

Thank you for your reply. I understand there is no easy way to achieve what I want. Hence I will just leave it as is and focus on the content of the report.

1 Like