global knitr options for ALL chapters in bookdown

Hello,

Is there a way to set global knitr options for ALL chapters in bookdown?

Currently, I'm setting global knitr options for each chapter (Rmd file) to specify a figure width and length. I was wondering if there's a easier way to set global knitr options for ALL the chapters at once.

1 Like

How are you setting those options ?
Which configuration are you changing in your project (in _bookdown.yaml for example) ?

You should be able to change knitr option once using a chunk in index.Rmd when you are using new_session = FALSE. You need to apply them per file if you are using new_session = TRUE because each file is knitted independently. However, in that case, you can create a file with the common R code and load this file in each document (for example using this 16.2 Read external scripts into a chunk | R Markdown Cookbook)

For figure width and length, you should be able to pass the option as argument to the function as with usual HTML format

output:
  bookdown::gitbook:
    fig_width: 10
    fig_height: 20

Hope it helps

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.