Bookdown caching

Is there a way to set cache=TRUE globally for all chunks in all .Rmd files of a bookdown book or does knitr::opts_chunk$set(cache=TRUE) need to be in every .Rmd file?

By default, bookdown use a Merge and Knit strategy. That means any code you wrote in setup chunk in index.Rmd for example, would apply to all the documents. other strategy is knit and merge.
See the doc https://bookdown.org/yihui/bookdown/new-session.html

In the knit and merge strategy, you would do that by configuring the option before_chapter_script:

This is a script executed before each chapter and would apply to the knitting of the chapter. I think this would work.

do you know already which strategy you are using (after reading the doc) ?

See the exemple of R4DS book

2 Likes

This all makes a lot of sense. I have been using the M-K default. I am indifferent to the considerations listed: duplicate labels, objects carried over from one .Rmd to the next, use of subdirectories for .Rmd files. In that case is there a recommended approach? Also, with M-K is it recommended to put all the library calls in index.Rmd? I tend to repeat them in each chapter, though clearly it's not necessary.

M K is fine. This is the easiest.

You can definitely to that. It is a good way to centralise everything for the projet.
However, having the library in each chapter make them indépendant and you can switch approach if needed. As you want ! :man_shrugging:

1 Like

Cool. I'm going to bet on M-K being faster and will therefore stick with it.

1 Like