r - tufte_html 格式可以在 bookdown/rmarkdown 中拆分为章节吗?

标签 r r-markdown knitr bookdown

是否可以将 R tufte 包中的 tufte_html 文档拆分为每章一个文件?我想写一整本书。 Bookdown 允许我在自己的文件中组织章节,并且章节在 pdf 输出中开始新页面,但对于 html 输出,它只是一个文件。

这是我尝试过的方法,但不起作用。

index.Rmd

---
title: "Probability and Statistics<br />"
author: "Bob Carpenter"
date: "2018"
output:
  tufte::tufte_html
---

```{r setup, include=FALSE}
bookdown::tufte_html_book(split_by = "chapter")
```

# A Chapter

Blah blah blah.

# Another Chapter

Blah blah blah.
```

_bookdown.yml

rmd_files: [
  "index.Rmd",
  "another_file.Rmd"
]

another_file.Rmd

# Yet another chapter

Foo bar baz.



$ R
> library(bookdown)
> render_book("index.Rmd")

这会生成一个 html 文档作为输出,而不是每章一个文件。我还尝试用 bookdown::tufte_html_book(split_by = "chapter") 替换 split_by 调用。

这是我的sessionInfo()

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] bookdown_0.7

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18    tufte_0.4       digest_0.6.15   rprojroot_1.3-2
 [5] backports_1.1.2 magrittr_1.5    evaluate_0.10.1 stringi_1.2.2  
 [9] rstudioapi_0.7  rmarkdown_1.10  tools_3.5.0     stringr_1.3.1  
[13] xfun_0.1        yaml_2.2.0      compiler_3.5.0  htmltools_0.3.6
[17] knitr_1.20  

最佳答案

我不太明白您在 index.Rmdsetup block 中尝试执行的操作,但这不是指定输出格式的正确方法R Markdown 。这是工作示例:

index.Rmd:

---
title: "Probability and Statistics<br />"
author: "Bob Carpenter"
date: "2018"
output:
  bookdown::tufte_html_book:
    split_by: chapter
---

# A Chapter

Blah blah blah.

# Another Chapter

Blah blah blah.

another_file.Rmd:

# Yet another chapter

Foo bar baz.

渲染这本书:

bookdown::render_book('index.Rmd')

关于r - tufte_html 格式可以在 bookdown/rmarkdown 中拆分为章节吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52483645/

相关文章:

r - 根据knitr的输出格式评估 block

r - 按年份排序facet_wrap图的更简单方法

r - ggplot 每侧有 2 个 y 轴且具有不同的比例

R markdown 输出页面宽度

r-markdown - 更改默认 Beamer 幻灯片大小

latex - R Markdown 与 LaTex 中的 "newcommand"类似的功能?

pdf - 编织 PDF 时如何更改 kableExtra::spec_pointrange 的线条颜色

r - 将汇总值表与来自 'parent' 数据集的汇总变量相结合

r - 计算熵

r - R MarkDown 和 R NoteBook 之间的区别