使用R / bookdown渲染tufte_html_book()时出错

时间:2017-10-08 07:57:44

标签: r bookdown tufte

我正在尝试使用R / bookdown构建一本书,并且在使用tufte_html_book或html_book制作html版本时遇到问题:

Error in split_chapters(output, page_builder, number_sections, split_by,  : 
  The document must start with a first (#) or second level (##) heading

本书是在gitbook或tufte_book2输出中正确生成的。 该文档包含四个文件index.Rmd01-Chap1.Rmd02-Chap2.Rmd03-Chap3.Rmd。我喜欢保持清晰,所以index.Rmd只包含YAML标题,加上一些R代码但没有标题,这可能是产生错误的原因。有没有办法让bookdown的html输出与gitbook或pdf输出类似?

这是一个可重复的小例子:

Index.Rmd:

---
title: "Tufte Handout"
subtitle: "An implementation in R Markdown"
author: "JJ Allaire and Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
  bookdown::tufte_html_book:
    toc: yes
bookdown::tufte_book2:
    toc: yes
---

```{r setup1, include=FALSE}
library(tufte)
# invalidate cache when the tufte version changes
knitr::opts_chunk$set(tidy = FALSE, cache.extra = 
packageVersion('tufte'))
options(htmltools.dir.version = FALSE)
```

01-Chap1.Rmd

# Introduction

The Tufte handout style is a style that Edward Tufte uses in his books and handouts. Tufte's style is known for its extensive use of sidenotes, tight integration of graphics with text, and well-set typography. This style has been implemented in LaTeX and HTML/CSS^[See Github repositories [tufte-latex](https://github.com/tufte-latex/tufte-latex) and [tufte-css](https://github.com/edwardtufte/tufte-css)], respectively. We have ported both implementations into the [**tufte** package](https://github.com/rstudio/tufte). If you want LaTeX/PDF output, you may use the `tufte_handout` format for handouts, and `tufte_book` for books. 
For HTML output, use `tufte_html`. These formats can be either specified in the YAML metadata at the beginning of an R Markdown document (see an example below), or passed to the `rmarkdown::render()` function. See @R-rmarkdown more information about **rmarkdown**.

1 个答案:

答案 0 :(得分:0)

我正在回答我自己的问题。

gitbook和(tufte_)html_book之间的行为差​​异在split_by参数中,即gitbook中的split_by="chapter"和(tufte_)html_book中的split_by="section"。将split_by: chapter添加到bookdown::tufte_html_book: yaml部分可以毫无错误地构建html。