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

标签 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 header ,加上一些 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**.

最佳答案

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

gitbook 和 (tufte_)html_book 之间的行为差​​异在于 split_by 参数,在 gitbook 中为 split_by="chapter" ,在 中为 split_by="section" (tufte_)html_book。将 split_by:chapter 添加到 bookdown::tufte_html_book: yaml 部分允许构建 html,不会出现错误。

关于r - 使用 R/bookdown 渲染 tufte_html_book() 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46628788/

相关文章:

r - 在 R 中将 UTF-8 BOM 导出为 .csv

r - 有没有办法在 R 中返回操作系统编号格式

r-markdown - 如何在 bookdown::pdf_document2 中使用 roboto 字体?

r - 针织簇绒交叉引用失败

python - 连接外显子序列并在其间插入 Ns

r - write.csv 用于大数据.table

css - 如何在带有 HTML 输出的 tufte-style Bookdown 中的每一章重置旁注编号?

r - Tufte html 输出中主列中的 DT::datatable

r-markdown - 在 Rmarkdown 中,有没有办法只为文档中引用的那些键创建 .bib 文件?

r - 如何防止bookdown删除.Rmd文件?