5.2 Preview a chapter
Building the whole book can be slow when the size of the book is big. Two things can affect the speed of building a book: the computation in R code chunks, and the conversion from Markdown to other formats via Pandoc. The former can be improved by enabling caching in knitr using the chunk option
cache = TRUE, and there is not much you can do to make the latter faster. However, you can choose to render only one chapter at a time using the function
preview_chapter() in bookdown, and usually this will be much faster than rendering the whole book. Only the Rmd files passed to
preview_chapter() will be rendered.
Previewing the current chapter is helpful when you are only focusing on that chapter, since you can quickly see the actual output as you add more content or revise the chapter. Although the preview works for all output formats, we recommend that you preview the HTML output.
One downside of previewing a chapter is that the cross-references to other chapters will not work, since bookdown knows nothing about other chapters in this case. That is a reasonably small price to pay for the gain in speed. Since previewing a chapter only renders the output for that specific chapter, you should not expect that the content of other chapters is correctly rendered as well. For example, when you navigate to a different chapter, you are actually viewing the old output of that chapter (which may not even exist).