Skip to content

Bookdown

Thomas J. Brailey edited this page Jun 8, 2020 · 8 revisions

Overview

  • Bookdown is an R package that allows to create articles, dissertations, and books in R.
  • Bookdown's infrastructure is similar to Blogdown, so those who have made their own websites with R/Hugo/Blogdown will be familiar with the mix of .Rmd, .yml, and .html files, as well as the overall project structure.
    • More specifically: most of the files in the Bookdown project needn't be worried about. There is a .travis.yml, _output.yml and _bookdown.yml file, and _build.sh and _deploy.sh file, and style and toc .css files. The rest of the files in the project are optional: the .Rmds, any BibTeX files, and so on.
  • The writing portion of Bookdown takes place in an .Rmd file, and any analysis and relevant outputs go inside an R chunk.

Packages

  • There are several packages that are well integrated into the Bookdown infrastructure.
    • knitr::kable and kableExtra:: allow you to integrate LaTeX and html tables with R. See here for a guide on producing tables in R markdown files.
  • Also mentioned in the tables guide, the package DT allows for interactive tables when exporting your Bookdown project to html.
  • Of course, ggplot2 objects and other visualization packages can be easily formatted in .Rmd and Bookdown.

Creating bibliographies

  • knitr::kable and kableExtra:: are super useful when creating tabulated literature reviews, as these packages work well with both the Bookdown format and BibTeX. Here is the workflow for generating summary literature reviews:
    • In a Google Sheet/Excel Sheet, create a table that contains columns for the BibTeX citations, and other salient information (i.e. authors, exact date, datasets used, main arguments, issues with paper, relationships with other articles, summary statistics, and the like). Note that the BibTeX citation should take the format [@AuthorTitleTitleTitleYear].
    • Read this sheet into your .Rmd file in your Bookdown project.
    • Make any necessary adjustments using tidyverse.
    • Use kable and kableExtra to print the table when the .Rmd is compiled.
    • The BibTeX citations will now link to a full citation of the article in the references section of the .Rmd.

Possible issues

  • One of the biggest issues with the Bookdown workflow is having to manually knit each chapter. If these chapters have a lot of analysis, plots, text, citations, and so on, knitting can take a long time. This makes the task of manually tweaking aesthetics and other small changes fairly inefficient. Additionally, issues may arise if one doesn't rerun the index file in the Bookdown project prior to rerunning the whole project. Again, this makes the process of updating the project to fix minor tweaks quite frustrating.
    • One option is to open the knitted .Rmd file in a Google Chrome tab, and then as you save your work in R, you can refresh the Chrome tab to see updates to that particular file rather than knitting the whole thing from scratch.
    • Another option is to start by writing the .Rmd files individually and then, once they are finished, save them into the Bookdown project. Then you can compile the whole project.

Examples

Further resources

Clone this wiki locally