Multiple bookdown books

Is there a way to generate multiple books that differ based on a single parameter value? Let's say I want to generate book1.pdf using data1 and then book2.pdf uses data2, which is data1 with some filtering applied to remove certain observations.

In terms of API usage,
in _bookdown.yml, there would be a vector of filenames for book_filename.
Maybe params would be passed to rmarkdown::render()?

If this is not possible, then I'd have to simply combine the two books with all the analyses shown using both data1 and data2, but this would double the length and make the report very long.

Another option I can think of is to create a branch where data2 is used to generate the report, and then I can switch between branches to generate the one that uses data1. Then at a later date when the project starts to mature we may choose to move forward with using only one of these.

A parametrized report, which you alluded to in your question, would be one way to do this. The link provides examples from the book R Markdown: The Definitive Guide. Also see this StackOverflow answer for an additional example.

Thanks @joels I implemented a solution by using params in my index.Rmd. I am able to generate separate bookdown::pdf_book outputs by passing different file names to output_file of bookdown::render_book(). However, the same cannot be done for the bookdown::gitbook output because I am using split_by: chapter+number. Therefore, I need to set output_file to NULL, and subsequently whenever I regenerate using different params it overwrites the previous website. Is there any way to keep 2 sets of html files?

I'm not sure, as I haven't used the gitbook output options.

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