Switching off file_scope in rmarkdown v23

My RMarkdown book contains sections with the same name (e.g., Questions) in several Chapters.

When I build this book with bookdown (0.20) and rmarkdown 2.3 to a gitbook (in RStudio 1.3.959), the pandoc command contains the --file-scope argument. As a consequence, the automatically generated HTML anchors of the sections only add sequence numbers (e.g., #questions-1, #questions-2) within a chapter (hmtl file), not across chapters. All entries in the table of contents to a Questions Section in a later chapter of the book refer to the first Questions Section in the first chapter. I guess this is an unintended side-effect of introducing the file_scope option in rmarkdown 2.3.

Note that this problem does not occur if I build the book with rmarkdown 2.2.

How can I turn the file_scope option off? I did not succeed in turning it off via file_scope: false in _output.yml, _bookdown.yml, or via the YAML of index.RMD.

Hi !

You can update to current bookdown development version has now file scope is disabled by default.

You can also in 0.20 use

options(bookdown.render.file_scope = FALSE)

as stated in the NEWS file linked above. This should disable the file scope feature.

Thanks, cderv, for the quick response. Apologies for not checking out the bookdown development pages first.

With rmarkdown v2.3 and bookdown v0.20, I can't get options(bookdown.render.file_scope = FALSE) to work if I add it to the first R code chunk in index.Rmd. The --file-scope argument is still added to the pandoc command.

The bookdown development version (0.20.6) does not use the --file-scope argument, as intended. Great!

1 Like

I think you need to set this option in your R session, before rendering. This is not read from you rmarkdown document when rendering - This is rather an option about bookdown rendering that needs to be set before using bookdown.

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.