Skip to Content
R在数据科学中的应用,第2版
book

R在数据科学中的应用,第2版

by Hadley Wickham, Mine Cetinkaya-Rundel, Garrett Grolemund
May 2025
Intermediate to advanced
578 pages
8h 9m
Chinese
O'Reilly Media, Inc.
Content preview from R在数据科学中的应用,第2版

第 29 章 四开本格式

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

导言

到目前为止,你已经看到 Quarto 用于制作 HTML 文档。本章将简要介绍使用 Quarto 可以生成的其他多种输出类型。

有两种方法可以设置文档的输出:

  • 通过修改 YAML 标头,永久性删除:

    title: "Diamond sizes"
    format: html
  • 瞬时,通过手动呼叫quarto::quarto_render()

    quarto::quarto_render("diamond-sizes.qmd", output_format = "docx")

    由于output_format 参数也可以接受一个值列表,因此如果要在程序中生成多种类型的输出,这一点非常有用:

    quarto::quarto_render(
      "diamond-sizes.qmd", output_format = c("docx", "pdf")
    )

输出选项

Quarto 提供多种输出格式。您可以在Quarto 文档中找到所有格式的完整列表。许多格式共享某些输出选项(例如,toc: true ,用于包含目录),但其他格式则有特定的选项(例如,code-fold: true ,将代码块折叠成<details> 标签,用于 HTML 输出,以便用户按需显示;这不适用于 PDF 或 Word 文档)。

要覆盖默认选项,需要使用扩展的format 字段。例如,如果您想渲染一个 HTML 文档,并带有浮动目录,您可以使用

format:
  html:
    toc: true
    toc_float: true

您甚至可以通过提供格式列表,渲染成多种输出格式:

format:
  html:
    toc: true
    toc_float: true
  pdf: default
  docx: default

如果不想覆盖任何默认选项,请注意特殊语法 (pdf: default)。

要呈现文档 YAML 中指定的所有格式,可以使用output_format = "all"

quarto::quarto_render("diamond-sizes.qmd", output_format = "all")

文件

上一章主要介绍了html 的默认输出。该主题有几种基本变体,可生成不同类型的文件。例如

  • pdf 您需要安装 LaTeX(一种开源文档排版系统)来制作 PDF。如果您还没有安装,RStudio 会提示您。

  • docx 用于 Microsoft Word ( ) 文档。.docx

  • odt 用于 OpenDocument Text ( ) 文档。.odt

  • rtf 富文本格式 ( ) 文档。.rtf

  • gfm 的 GitHub Flavored Markdown ( ) 文档。.md

  • ipynb Jupyter Notebooks ( )。.ipynb

请记住,在生成要与决策者共享的文档时,您可以通过在文档 YAML 中设置全局选项来关闭代码的默认显示:

execute:
  echo: false

对于 HTML 文档,另一种方法是让代码块默认为隐藏,但点击后可见:

format:
  html:
    code: true

演讲

你还可以使用 Quarto 制作演示文稿。与 Keynote 或 PowerPoint 等工具相比,Quarto 的可视化控制能力较弱,但自动将 R 代码结果插入演示文稿可以节省大量时间。演示文稿的工作原理是将内容分割成幻灯片,每张新幻灯片从二级标题 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen
Raku学习手册

Raku学习手册

brian d foy

Publisher Resources

ISBN: 9798341657304