Brett Klamer

Compile R for Data Science to a PDF

R for Data Science by Hadley Wickham and Garrett Grolemund introduces a modern workflow for data science using tidyverse packages from R. The source is available on GitHub and a version compiled for the web is at http://r4ds.had.co.nz/. Even though the HTML format is nice, I still like to have a PDF around. Here’s how to compile it from the source. (Please consider buying a copy to support their work.)

These instructions assume you are using a Debian based OS and have R, LaTeX, and pandoc installed.

  1. Download the repository from https://github.com/hadley/r4ds

  2. From R, run

    devtools::install_github("hadley/r4ds")
    devtools::install_github("wch/webshot")
    
  3. From the command line, run

    sodu apt install phantomjs
    
  4. From TeX Live (or whatever TeX manager you use) make sure framed and titling are installed

    sudo env PATH="$PATH" tlmgr --gui
    
  5. Compile the book using

    # PDF
    bookdown::render_book("index.Rmd", output_format = "bookdown::pdf_book")
    # Static website
    bookdown::render_book("index.Rmd", output_format = "bookdown::gitbook")
    

My resulting PDF is 10.9MB and 412 pages as of 2016-10-31.

Published: 2016-10-31