-
Notifications
You must be signed in to change notification settings - Fork 7
03 Building books with bookdown
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.
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.
You can install the package from CRAN by running the following R code in the RStudio console:
install.packages("bookdown")
When you start using the Data Privacy Handbook locally, you can follow the following steps:
- Open the dataprivacyhandbook.RProj file, either by clicking on the file in the file viewer, or by opening it via RStudio (File > Open project).
- Edit files where needed (see section on file structure)
- 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. - 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.