Skip to Content
R for Data Science
book

R for Data Science

by Hadley Wickham, Garrett Grolemund
December 2016
Beginner to intermediate
520 pages
10h 12m
English
O'Reilly Media, Inc.
Content preview from R for Data Science

Chapter 23. R Markdown Formats

Introduction

So far you’ve seen R Markdown used to produce HTML documents. This chapter gives a brief overview of some of the many other types of output you can produce with R Markdown. There are two ways to set the output of a document:

  1. Permanently, by modifying the the YAML header:

    title: "Viridis Demo"
    output: html_document
  2. Transiently, by calling rmarkdown::render() by hand:

    rmarkdown::render(
      "diamond-sizes.Rmd",
      output_format = "word_document"
    )

    This is useful if you want to programmatically produce multiple types of output.

RStudio’s knit button renders a file to the first format listed in its output field. You can render to additional formats by clicking the drop-down menu beside the knit button.

rfds 23in01

Output Options

Each output format is associated with an R function. You can either write foo or pkg::foo. If you omit pkg, the default is assumed to be rmarkdown. It’s important to know the name of the function that makes the output because that’s where you get help. For example, to figure out what parameters you can set with html_document, look at ?rmarkdown:html_document().

To override the default parameter values, you need to use an expanded output field. For example, if you wanted to render an html_document with a floating table of contents, you’d use:

output:
  html_document:
    toc: true
    toc_float: true

You can even render to multiple ...

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 for Data Science, 2nd Edition

R for Data Science, 2nd Edition

Hadley Wickham, Mine Çetinkaya-Rundel, Garrett Grolemund
Data Science for Business

Data Science for Business

Foster Provost, Tom Fawcett
Python and R for the Modern Data Scientist

Python and R for the Modern Data Scientist

Rick J. Scavetta, Boyan Angelov

Publisher Resources

ISBN: 9781491910382Errata Page