编译ggplot电子书


Hadley把他编写的ggplot2: Elegant Graphics for Data Analysis书的源文件晒到了 Github上。按照README编译过程中发现了 一些问题,所以将编译过程记录下来作为备忘。

克隆库
git clone https://github.com/hadley/ggplot2-book.git
安装依赖

安装包

library(devtools)
if (packageVersion("devtools") < "1.9.1") {
  message("Please upgrade devtools")
}
devtools::install_deps('.')

# 需要注意的是编译ggplot需要bklamer的oldbookdown,不是bookdown
devtools::install_github("bklamer/oldbookdown")
修改/book/render-tex.R

oldbookdown::tex_chapter() 中使用了参数--chapters,而目前pandoc已经把该参数改为--top-level-division=chapter, 修改/book/render-tex.R

library("methods") # avoids weird broom error
library("rmarkdown")

tex_chapter <- function (chapter = NULL, latex_engine = c("xelatex", "pdflatex",
  "lualatex"), code_width = 65)
{
  options(digits = 3)
  set.seed(1014)
  latex_engine <- match.arg(latex_engine)
  rmarkdown::output_format(rmarkdown::knitr_options("html", chapter),
    rmarkdown::pandoc_options(to = "latex",
      from = "markdown_style", ext = ".tex",
      args = c("--top-level-division=chapter",
      rmarkdown::pandoc_latex_engine_args(latex_engine))),
    clean_supporting = FALSE)
}

path <- commandArgs(trailingOnly = TRUE)
# command line args should contain just one chapter name
if (length(path) == 0) {
  message("No input supplied")
} else {
  base <- tex_chapter()
  base$knitr$opts_knit$width <- 67
  base$pandoc$from <- "markdown"

  rmarkdown::render(path, base, output_dir = "book/tex", envir = globalenv(), quiet = TRUE)
}

安装0.2.0版本USAboundaries

目前cran上为0.3.0版本

devtools::install_version(package = "USAboundaries", version = "0.2.0")
编译
cd ggplot2-book
make clean
make

PDF电子书生成/book/tex/ggplot2-book.pdf

Reference

https://github.com/hadley/ggplot2-book/issues/134


一路嘿嘿

Bioinformatics, R enthusiast. Thoughts on reasarch, personal experience and other distractions.

Tags

blogdown font ggplot git github github pages Homebrew html hugo icon liner algebra linux machine learning R scholar sublime text 3 tidyverse