-
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 as follows:
install.packages("bookdown")
- First of all, the package was loaded using the following command:
library(bookdown)
- For the Handbook, the first step was to create a skeleton project using the following command:
bookdown:::bookdown_skeleton(getwd())
-
The above command does not generate a R Project (.Rproj) file. This was created manually by going to File -> New Project... -> Existing Directory ->
dataprivacyhandbook.Rproj
-
R Markdown (.Rmd) files were added per chapter.
-
Specifications in the
_bookdown.yml
page were edited as follows:
-
book_filename:
was specified as"dataprivacyhandbook"
-
output_dir:
was added and set to"docs"
(instead of the default"_book"
directory) -
chapter_name:
was set to""
- Specifications in the
_output.yml
page were edited as follows:
-
number_sections:
was added and set tofalse
-
split_by:
was added and set tosection
-
collapse:
was added undertoc
and set tosection
-
before:
was set to<li><a href="./">Data Privacy Handbook</a></li>
-
after:
was set to<li><a href="https://github.com/UtrechtUniversity/dataprivacyhandbook" target="blank">Visit the GitHub repository</a></li>
- The book was then rendered using the following command:
bookdown::render_book("index.Rmd", "bookdown::gitbook")