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:
-
Permanently, by modifying the the YAML header:
title
:
"Viridis
Demo"
output
:
html_document
-
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.
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 ...
Get R for Data Science now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.