Skip to content

03 Building books with bookdown

Dorien Huijser edited this page Jan 13, 2025 · 13 revisions

While individual chapters are written as R Markdown (.Rmd) files, these are rendered to HTML and compiled into a 'book' using the bookdown package in R.

The bookdown package is built on top of R Markdown, and inherits the simplicity of the Markdown syntax, as well as the possibility of multiple types of output formats (HTML, PDF, Word). It has also added features like multi-page HTML output, numbering and cross-referencing figures/tables/sections/equations, inserting parts/appendices to create elegant and appealing HTML book pages.

The Handbook is an example of how you can produce a 'book' from a series of R Markdown documents meant to be read in a linear sequence.

Usage

Thanks to our CI/CD workflow (outlined in the next Wiki page), you don't necessarily have to build the book locally on RStudio. You can do it for your own convenience of course, for example, if you want to preview your edits as you go.

The following section outlines the initial setup, so current and future maintainers know how the book was tailored to our needs.

Installation

You can install the package from CRAN by running the following R code in the RStudio console:

install.packages("bookdown")

Initial Setup

When you start using the Data Privacy Handbook locally, you can follow the following steps:

  1. Open the dataprivacyhandbook.RProj file, either by clicking on the file in the file viewer, or by opening it via RStudio (File > Open project).
  2. Edit files where needed (see section on file structure)
  3. Click Render in the top right Build window. Alternatively, you can render the book by running bookdown::render_book("index.Rmd") in the RStudio console.
  4. A preview of the book will open automatically (in RStudio itself, or in your browser, depending on your settings). If not, you can click on one of the created html files to see your edits locally.

References

  1. bookdown: Authoring Books and Technical Documents with R Markdown
  2. https://github.com/rstudio/bookdown
  3. https://bookdown.org/