【问题标题】:Error when rendering tufte_html_book() with R/bookdown使用 R/bookdown 渲染 tufte_html_book() 时出错
【发布时间】:2017-10-08 07:57:43
【问题描述】:

我正在尝试使用 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 输出?

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

索引.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**.

【问题讨论】:

  • 你应该给出一个可重现的例子。也许您可以只留下index.Rmd01-Chap1.Rmd,并尽可能减少它们的内容,同时可以产生相同的示例。然后粘贴这两个文件的代码。
  • 是否可以使用这种方法生成 tufte pdf 书?
  • 是的。只需将 bookdown::tufte_book2 保留在 yaml 中即可。

标签: r bookdown tufte


【解决方案1】:

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

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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多