Compiling the ggplot2 book on Mac OS
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
This note explains to compile Hadley Wickham’s ggplot2 book on Mac OS.
This guide has 8 steps. If you have already installed R and RStudio, you should be able to get through Steps 1-4 very quickly. Similarly, if you use Git, Steps 5-6 should also be very straightforward.
The longest steps are Step 7 (package dependencies) and Step 8 (book compilation).
1. Install the Command Line Tools
If you have not yet done so, install the Command Line Tools (CLTs) for your version of Mac OS X (now called macOS). Since the CLTs are required to build packages with RStudio, there is a fair chance that you have already installed them.
The CLTs are located in the list of Apple Developer downloads, and you will need an account to log in. Alternately, you can also download Xcode from the Mac App Store, but that software requires much, much more disk space.
2. Install MacTeX
If you have not yet done so, install the latest version of MacTeX, the standard LaTeX distribution for Mac.
Then, open the TeX Live Utility located with the rest of your TeX applications, and make sure that the inconsolata
monospaced font package has been installed; otherwise, install it now.
3. Install Homebrew
Homebrew is a package manager that makes it very easy to install all sorts of software.
If you have not yet installed it, do it now, using the single line of code on the home page of the Homebrew website.
4. Install Pandoc
Since you have installed Homebrew at Step 3, you can now easily install the Pandoc document conversion system by running the following commands from the Terminal:
5. Install Git and GitHub Desktop
If you have not yet installed them, install both Git and GitHub Desktop, two versioning tools that work hand in hand with each other.
You do not really need those tools to build the book, but since the book is still being updated, they will make it easy to pull future updates and rebuild the book then.
6. Clone the book repository
Clone the ggplot2-book
repository to your hard drive.
As Hadley Wickham suggests, you can do that from the command line:
Alternately, you can use the “Clone or download > Open in Desktop” buttons that you will see on the GitHub page of the repository if you have installed GitHub Desktop:
7. Install package dependencies
You now need to install the many package dependencies of the book.
Hadley Wickham suggests doing so by using devtools
from within the ggplot2-book
repository, using the following code:
If you have both RStudio and a recent version of devtools
installed, just double-click the ggplot2-book.Rproj
file in the ggplot2-book
folder, copy-paste the last line of code above to the Console, and press Enter
to execute.
Note that the book uses an old version of the bookdown
package, and therefore requires one more package installation to compile properly. Brett Klamer has set up a patched version of the package to ease that step:
8. Compile the book
Last, compile the book by running its Makefile
from the Terminal:
The Makefile
is located at the root of the ggplot2-book
repository.
The book should be ready in less than 30 minutes, depending on how fast your computer is at compiling large quantities of LaTeX laced with lots of R code. Compilation took 23 minutes on my 2012 MacBook Air with 8GB of RAM.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.