Search code examples
rr-markdownbookdown

How to conditionally process sections in Rmarkdown


I have a book I'm generating with bookdown where I want to conditionally include a section of a chapter only when publishing to html as the section has animations in it. I can't find documentation on this. Can someone please point me towards relevant doc?


Solution

  • If the section is in a separate file, you can use _bookdown.yml file in the book directory to specify which files to use and which order to compile them depending on rendering format.

    rmd_files:
      html: ["index.Rmd", "abstract.Rmd", "intro.Rmd"]
      latex: ["abstract.Rmd", "intro.Rmd"]
    

    (from Chapter 1.3 Usage of the bookdown manual)