【问题标题】:Can tufte_html format be split into chapters in bookdown/rmarkdown?tufte_html 格式可以拆分成 bookdown/rmarkdown 中的章节吗?
【发布时间】:2019-02-28 05:16:37
【问题描述】:

是否可以将 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 文档作为输出,而不是每章一个文件。我还尝试将 split_by 调用替换为 bookdown::tufte_html_book(split_by = "chapter")

这是我的sessionInfo()

> 会话信息() R 版本 3.5.0 (2018-04-23) 平台:x86_64-apple-darwin15.6.0(64位) 运行于:macOS High Sierra 10.13.6 矩阵产品:默认 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 语言环境: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 附加的基础包: [1] stats graphics grDevices utils datasets methods base 其他附加包: [1] bookdown_0.7 通过命名空间加载(未附加): [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 编译器_3.5.0 htmltools_0.3.6 [17] knitr_1.20

【问题讨论】:

    标签: r r-markdown knitr bookdown


    【解决方案1】:

    我不太明白您在 index.Rmdsetup 块中尝试做什么,但这不是在 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')
    

    【讨论】:

    • 非常感谢您提供了一个有效的示例。我没有意识到有一个 tufte_html_book 选项,或者我可以将 split_by 放在 yaml 中。是否有详尽的预订选项列表,然后是 tufte_html_book 等选项?我尝试设置的原因是我在网上搜索的唯一答案指向html_chapters 函数。
    • @BobCarpenter 像?bookdown::tufte_html_book 这样的帮助页面列出了函数参数。这些参数对应于 YAML 标头。
    猜你喜欢
    • 2018-03-30
    • 2019-05-09
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    相关资源
    最近更新 更多