4

Short version: Is it possible to set Rstudio bookdown so that, when using html output, it doesn't rebuild unchanged Rmd files and instead uses the existing html files (kind of like make)?

Long version: I am using bookdown in RStudio to keep a project notebook. I create a separate Rmd file for each day, and have set new_session: yes in _bookdown.yml.

Ideally, the output should be "locked" at the end of the day, so that it accurately reflects that day's work, including that day's environment (which might be different from the current environment, as I update scripts and data). In particular, when I rebuild the book, I don't want the page from (say) a month ago to change (the one exception being if I add a deprecatory note about a subsequently-discovered error).

I can prevent the R code chunks from re-running by inserting knitr::opts_chunk$set(cache = TRUE) into the first code chunk of each file. However, when I rebuild the book, each Rmd file is still converted to md and then to html, which is getting time consuming as my notebook grows! I realize that I don't need to rebuild the book to knit the current chapter, but periodic rebulding is desirable to keep the table of contents and search index up to date.

It would be great if there were a way for the rebuild to just re-use the existing html files for chapters that hadn't been changed. I realize that a potential challenge with this (and why there probably isn't a simple solution using make) is keeping track of what to include in the toc of index.html, as well as updating search_index.json appropriately. Actually, now that I inspect the html files for the individual chapters, I see that the toc is coded into each one of them. So any solution would need a different architecture where the toc lived in a separate file.

Anyhow, just thought I'd see if there were either a hidden option or a workaround out there!

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Sure, instead of sourcing the Rmd file, comment it out during your development of the notebook and instead source the HTML output of the Rmd. Or if you want to selectively include your Rmd documents, create a variable at the top of the file which stores a zero or one to source the Rmd files, or source html, and use an ifelse statement based on that variable to load the appropriate document when you compile the new bookdown script. – sconfluentus Apr 29 '17 at 04:30
  • @sconfluentus Thanks for that suggestions, but I don't explicitly list the Rmd files anywhere, as they are named with the date and so sort automatically into the desired order. I'm also not sure how to "source the HTML output" (I'm relatively new to bookdown, but don't recall seeing that mentioned in Yihui's book). Finally, it doesn't seem like this would update the table of contents in the old HTML files? – Bruce Kendall Apr 30 '17 at 13:51
  • I should add that I have been using the knit and build shortcuts in Rstudio to access `preview_chapter()` and `render_book()` respectively. I need to explore the extent to which `serve_book()` would fit my needs. However, as section 5.4 of the bookdown manual says, periodic rebuilding will still be needed. I'm looking towards the time when I have hundreds of daily Rmd files, and the fact that each call to Pandoc seems to take a finite time. – Bruce Kendall Apr 30 '17 at 13:59
  • You can include almost anything using HTML, so you could insert another page using a link with a local reference (pointed to a file in the same folder). But as you said, the table of contents for that chapter will not update in the older files unless you re-run the files, or the table of contents loads as a source from a text file dynamically using html. It may be more work than it is worth, depending on how you are using it. – sconfluentus Apr 30 '17 at 16:47
  • 1
    Any updates on this? I didn't really read a solution. I also don't explicitly list the Rmd files to be sourced, i just name them appropriately. – Robin Donatello Jan 17 '18 at 06:22

0 Answers0