Title: | Dynamic Documents for R |
---|---|
Description: | Convert R Markdown documents into a variety of formats. |
Authors: | JJ Allaire [aut], Yihui Xie [aut, cre] , Christophe Dervieux [aut] , Jonathan McPherson [aut], Javier Luraschi [aut], Kevin Ushey [aut], Aron Atkins [aut], Hadley Wickham [aut], Joe Cheng [aut], Winston Chang [aut], Richard Iannone [aut] , Andrew Dunning [ctb] , Atsushi Yasumoto [ctb, cph] (<https://orcid.org/0000-0002-8335-495X>, Number sections Lua filter), Barret Schloerke [ctb], Carson Sievert [ctb] , Devon Ryan [ctb] , Frederik Aust [ctb] , Jeff Allen [ctb], JooYoung Seo [ctb] , Malcolm Barrett [ctb], Rob Hyndman [ctb], Romain Lesur [ctb], Roy Storey [ctb], Ruben Arslan [ctb], Sergio Oller [ctb], Posit Software, PBC [cph, fnd], jQuery UI contributors [ctb, cph] (jQuery UI library; authors listed in inst/rmd/h/jqueryui/AUTHORS.txt), Mark Otto [ctb] (Bootstrap library), Jacob Thornton [ctb] (Bootstrap library), Bootstrap contributors [ctb] (Bootstrap library), Twitter, Inc [cph] (Bootstrap library), Alexander Farkas [ctb, cph] (html5shiv library), Scott Jehl [ctb, cph] (Respond.js library), Ivan Sagalaev [ctb, cph] (highlight.js library), Greg Franko [ctb, cph] (tocify library), John MacFarlane [ctb, cph] (Pandoc templates), Google, Inc. [ctb, cph] (ioslides library), Dave Raggett [ctb] (slidy library), W3C [cph] (slidy library), Dave Gandy [ctb, cph] (Font-Awesome), Ben Sperry [ctb] (Ionicons), Drifty [cph] (Ionicons), Aidan Lister [ctb, cph] (jQuery StickyTabs), Benct Philip Jonsson [ctb, cph] (pagebreak Lua filter), Albert Krewinkel [ctb, cph] (pagebreak Lua filter) |
Maintainer: | Yihui Xie <[email protected]> |
License: | GPL-3 |
Version: | 2.29.1 |
Built: | 2024-12-04 06:13:59 UTC |
Source: | https://github.com/rstudio/rmarkdown |
Convert R Markdown documents into a variety of formats including HTML, MS Word, PDF, and Beamer.
The rmarkdown package includes high level functions for converting to a variety of formats. For example:
render("input.Rmd", html_document()) render("input.Rmd", pdf_document())
You can also specify a plain markdown file in which case knitting will be bypassed:
render("input.md", html_document())
Additional options can be specified along with the output format:
render("input.Rmd", html_document(toc = TRUE)) render("input.Rmd", pdf_document(latex_engine = "lualatex")) render("input.Rmd", beamer_presentation(incremental = TRUE))
You can also include arbitrary pandoc command line arguments along with the other options:
render("input.Rmd", pdf_document(toc = TRUE, pandoc_args = "--listings"))
Maintainer: Yihui Xie [email protected] (ORCID)
Authors:
JJ Allaire [email protected]
Christophe Dervieux [email protected] (ORCID)
Jonathan McPherson [email protected]
Javier Luraschi
Kevin Ushey [email protected]
Aron Atkins [email protected]
Hadley Wickham [email protected]
Joe Cheng [email protected]
Winston Chang [email protected]
Richard Iannone [email protected] (ORCID)
Other contributors:
Andrew Dunning (ORCID) [contributor]
Atsushi Yasumoto (ORCID) (Number sections Lua filter) [contributor, copyright holder]
Barret Schloerke [contributor]
Carson Sievert (ORCID) [contributor]
Devon Ryan [email protected] (ORCID) [contributor]
Frederik Aust [email protected] (ORCID) [contributor]
Jeff Allen [email protected] [contributor]
JooYoung Seo (ORCID) [contributor]
Malcolm Barrett [contributor]
Rob Hyndman [email protected] [contributor]
Romain Lesur [contributor]
Roy Storey [contributor]
Ruben Arslan [email protected] [contributor]
Sergio Oller [contributor]
Posit Software, PBC [copyright holder, funder]
jQuery UI contributors (jQuery UI library; authors listed in inst/rmd/h/jqueryui/AUTHORS.txt) [contributor, copyright holder]
Mark Otto (Bootstrap library) [contributor]
Jacob Thornton (Bootstrap library) [contributor]
Bootstrap contributors (Bootstrap library) [contributor]
Twitter, Inc (Bootstrap library) [copyright holder]
Alexander Farkas (html5shiv library) [contributor, copyright holder]
Scott Jehl (Respond.js library) [contributor, copyright holder]
Ivan Sagalaev (highlight.js library) [contributor, copyright holder]
Greg Franko (tocify library) [contributor, copyright holder]
John MacFarlane (Pandoc templates) [contributor, copyright holder]
Google, Inc. (ioslides library) [contributor, copyright holder]
Dave Raggett (slidy library) [contributor]
W3C (slidy library) [copyright holder]
Dave Gandy (Font-Awesome) [contributor, copyright holder]
Ben Sperry (Ionicons) [contributor]
Drifty (Ionicons) [copyright holder]
Aidan Lister (jQuery StickyTabs) [contributor, copyright holder]
Benct Philip Jonsson (pagebreak Lua filter) [contributor, copyright holder]
Albert Krewinkel (pagebreak Lua filter) [contributor, copyright holder]
render, html_document, pdf_document, word_document, beamer_presentation
Read the YAML metadata (and any common output YAML file) for the
document and return the output formats that will be generated by
a call to render
.
all_output_formats(input, output_yaml = NULL)
all_output_formats(input, output_yaml = NULL)
input |
Input file (Rmd or plain markdown) |
output_yaml |
Paths to YAML files specifying output formats and their
configurations. The first existing one is used. If none are found, then
the function searches YAML files specified to the |
This function is useful for front-end tools that require additional
knowledge of the output to be produced by render
(e.g. to
customize the preview experience).
A character vector with the names of all output formats.
List the available template by name that can be used with draft()
to create
a new document for R Markdown from a package.
available_templates(package = "rmarkdown", full_path = FALSE)
available_templates(package = "rmarkdown", full_path = FALSE)
package |
Package to list template from. Default to rmarkdown |
full_path |
Set to |
A character vector of templates name to use within draft()
. If
full_path = TRUE
, it returns the full path to the templates.
# List rmarkdown templates & create a draft available_templates() # List rticles templates available_templates("rticles")
# List rmarkdown templates & create a draft available_templates() # List rticles templates available_templates("rticles")
Format for converting from R Markdown to a Beamer presentation.
beamer_presentation( toc = FALSE, slide_level = NULL, number_sections = FALSE, incremental = FALSE, fig_width = 10, fig_height = 7, fig_crop = "auto", fig_caption = TRUE, dev = "pdf", df_print = "default", theme = "default", colortheme = "default", fonttheme = "default", highlight = "default", template = "default", keep_tex = FALSE, keep_md = FALSE, latex_engine = "pdflatex", citation_package = c("default", "natbib", "biblatex"), self_contained = TRUE, includes = NULL, md_extensions = NULL, pandoc_args = NULL, extra_dependencies = NULL )
beamer_presentation( toc = FALSE, slide_level = NULL, number_sections = FALSE, incremental = FALSE, fig_width = 10, fig_height = 7, fig_crop = "auto", fig_caption = TRUE, dev = "pdf", df_print = "default", theme = "default", colortheme = "default", fonttheme = "default", highlight = "default", template = "default", keep_tex = FALSE, keep_md = FALSE, latex_engine = "pdflatex", citation_package = c("default", "natbib", "biblatex"), self_contained = TRUE, includes = NULL, md_extensions = NULL, pandoc_args = NULL, extra_dependencies = NULL )
toc |
|
slide_level |
The heading level which defines individual slides. By
default this is the highest header level in the hierarchy that is followed
immediately by content, and not another header, somewhere in the document.
This default can be overridden by specifying an explicit
|
number_sections |
|
incremental |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_crop |
Whether to crop PDF figures with the command
|
fig_caption |
|
dev |
Graphics device to use for figure output (defaults to pdf) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
theme |
Beamer theme (e.g. "AnnArbor"). |
colortheme |
Beamer color theme (e.g. "dolphin"). |
fonttheme |
Beamer font theme (e.g. "structurebold"). |
highlight |
Syntax highlighting style passed to Pandoc. Supported built-in styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock", and "breezedark". Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a path to a ‘.theme’ file to use a custom Pandoc style. Note that custom theme requires Pandoc 2.0+. Pass |
template |
Pandoc template to use for rendering. Pass "default" to use
the rmarkdown package default template; pass |
keep_tex |
Keep the intermediate tex file used in the conversion to PDF.
Note that this argument does not control whether to keep the auxiliary
files (e.g., ‘.aux’) generated by LaTeX when compiling ‘.tex’ to
‘.pdf’. To keep these files, you may set |
keep_md |
Keep the markdown file generated by knitting. |
latex_engine |
LaTeX engine for producing PDF output. Options are "pdflatex", "lualatex", "xelatex" and "tectonic". |
citation_package |
The LaTeX package to process citations, |
self_contained |
Whether to generate a full LaTeX document ( |
includes |
Named list of additional content to include within the
document (typically created using the |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
extra_dependencies |
A LaTeX dependency |
See the online documentation
for additional details on using the beamer_presentation
format.
Creating Beamer output from R Markdown requires that LaTeX be installed.
R Markdown documents can have optional metadata that is used to generate a document header that includes the title, author, and date. For more details see the documentation on R Markdown metadata.
R Markdown documents also support citations. You can find more information on the markdown syntax for citations in the Bibliographies and Citations article in the online documentation.
R Markdown output format to pass to render()
## Not run: library(rmarkdown) # simple invocation render("pres.Rmd", beamer_presentation()) # specify an option for incremental rendering render("pres.Rmd", beamer_presentation(incremental = TRUE)) ## End(Not run)
## Not run: library(rmarkdown) # simple invocation render("pres.Rmd", beamer_presentation()) # specify an option for incremental rendering render("pres.Rmd", beamer_presentation(incremental = TRUE)) ## End(Not run)
R Markdown can also compile R scripts to a notebook which includes commentary, source code, and script output. Notebooks can be compiled to any output format including HTML, PDF, and MS Word.
To compile a notebook from an R script you simply pass the script to
render
. For example:
rmarkdown::render("analysis.R") rmarkdown::render("analysis.R", "pdf_document")
The first call to render
creates an HTML document, whereas
the second creates a PDF document.
By default the name of the script, username, and current date and time are included in the header of the generated notebook. You can override this default behavior by including explicit metadata in a specially formatted R comment:
#' --- #' title: "Crop Analysis Q3 2013" #' author: "John Smith" #' date: "May 3rd, 2014" #' ---
Note that the R comment used above to add a title, author, and date includes a single-quote as a special prefix character. This is a roxygen2 style comment, and it's actually possible to include many such comments in an R script, all of which will be converted to markdown content within the generated notebook. For example:
#' A script comment that includes **markdown** formatting.
Rather than displaying as an R comment in the compiled notebook any roxygen2 style comment will be treated as markdown and rendered accordingly.
Including markdown within R comments is possible because render
calls the knitr spin
function to convert the R
script to an Rmd file. The spin
function also enables you to add
knitr
chunk options with another special comment prefix (#+
).
Here's an example of a script that uses the various features of spin
:
https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.R
For more details on knitr::spin
see the following documentation:
https://yihui.org/knitr/demo/stitch/
Format for converting from R Markdown to PDF using ConTeXt.
context_document( toc = FALSE, toc_depth = 2, number_sections = FALSE, fig_width = 6.5, fig_height = 4.5, fig_crop = "auto", fig_caption = TRUE, dev = "pdf", df_print = "default", template = NULL, keep_tex = FALSE, keep_md = FALSE, citation_package = c("default", "natbib", "biblatex"), includes = NULL, md_extensions = NULL, output_extensions = NULL, pandoc_args = NULL, context_path = NULL, context_args = NULL, ext = c(".pdf", ".tex") )
context_document( toc = FALSE, toc_depth = 2, number_sections = FALSE, fig_width = 6.5, fig_height = 4.5, fig_crop = "auto", fig_caption = TRUE, dev = "pdf", df_print = "default", template = NULL, keep_tex = FALSE, keep_md = FALSE, citation_package = c("default", "natbib", "biblatex"), includes = NULL, md_extensions = NULL, output_extensions = NULL, pandoc_args = NULL, context_path = NULL, context_args = NULL, ext = c(".pdf", ".tex") )
toc |
|
toc_depth |
Depth of headers to include in table of contents |
number_sections |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_crop |
Whether to crop PDF figures with the command
|
fig_caption |
|
dev |
Graphics device to use for figure output (defaults to pdf) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
template |
Pandoc template to use for rendering. Pass "default" to use
the rmarkdown package default template; pass |
keep_tex |
Keep the intermediate tex file used in the conversion to PDF.
Note that this argument does not control whether to keep the auxiliary
files (e.g., ‘.aux’) generated by LaTeX when compiling ‘.tex’ to
‘.pdf’. To keep these files, you may set |
keep_md |
Keep the markdown file generated by knitting. |
citation_package |
The LaTeX package to process citations, |
includes |
Named list of additional content to include within the
document (typically created using the |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
output_extensions |
Pandoc extensions to be added or removed from the
output format, e.g., |
pandoc_args |
Additional command line options to pass to pandoc |
context_path |
Path of the ConTeXt executable. If not provided, ConTeXt
has to be available from the |
context_args |
Command line arguments passed to ConTeXt. |
ext |
Format of the output document (defaults to ".pdf"). |
ConTeXt needs to be installed, e.g., you can install it with
tinytex::tlmgr_install("context")
.
R Markdown documents can have optional metadata that is used to generate a document header that includes the title, author, and date. For more details see the documentation on R Markdown metadata.
R Markdown documents also support citations. You can find more information on the markdown syntax for citations in the Bibliographies and Citations article in the online documentation.
R Markdown output format to pass to render
.
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", context_document()) ## End(Not run)
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", context_document()) ## End(Not run)
Read a Jupyter/IPython notebook file (‘.ipynb’) via
jsonlite::fromJSON()
, convert its code cells to R Markdown code
chunks, preserve Markdown cells, and write out the results to an Rmd file.
convert_ipynb(input, output = xfun::with_ext(input, "Rmd"))
convert_ipynb(input, output = xfun::with_ext(input, "Rmd"))
input |
Path to the input ‘.ipynb’ file. |
output |
The output file path. |
This simple converter may have some rough edges, depending on how many
IPython-specific features are used in a notebook. For example, line magics
are not automatically converted (warnings will be issued if line magics are
detected), but you may consider using or writing R functions to replace them
in R Markdown (e.g., the %load
magic may be replaced by
reticulate::source_python()
). Cell magics will be converted to code
chunks with the (knitr) language engine names being the magic names.
For example, the cell magic %%js
is converted to ```{js}
in R Markdown. This does not always work because not all IPython cell magics
have their counterparts in knitr's language engines, but common cell
magics like %%bash
, %%sh
, %%js
,
%%perl
, %%python
, and %%ruby
should work.
The output file path (invisibly).
# this is not a real ipynb file, but illustrates what convert_ipynb() does nb_data <- list( cells = list( list(cell_type = 'markdown', source = 'Hi **Markdown**!'), list(cell_type = 'code', source = 'print("Hi R Markdown!")') ), metadata = list( kernelspec = list(language = 'python') ) ) nb_file = tempfile(fileext = '.ipynb') jsonlite::write_json(nb_data, nb_file, auto_unbox = TRUE, pretty = TRUE) xfun::file_string(nb_file) # show file content # convert to R Markdown nb_rmd = rmarkdown:::convert_ipynb(nb_file) xfun::file_string(nb_rmd)
# this is not a real ipynb file, but illustrates what convert_ipynb() does nb_data <- list( cells = list( list(cell_type = 'markdown', source = 'Hi **Markdown**!'), list(cell_type = 'code', source = 'print("Hi R Markdown!")') ), metadata = list( kernelspec = list(language = 'python') ) ) nb_file = tempfile(fileext = '.ipynb') jsonlite::write_json(nb_data, nb_file, auto_unbox = TRUE, pretty = TRUE) xfun::file_string(nb_file) # show file content # convert to R Markdown nb_rmd = rmarkdown:::convert_ipynb(nb_file) xfun::file_string(nb_rmd)
Read the YAML metadata (and any common output YAML file) for the
document and return the output format that will be generated by
a call to render
.
default_output_format(input, output_yaml = NULL)
default_output_format(input, output_yaml = NULL)
input |
Input file (Rmd or plain markdown) |
output_yaml |
Paths to YAML files specifying output formats and their
configurations. The first existing one is used. If none are found, then
the function searches YAML files specified to the |
This function is useful for front-end tools that require additional
knowledge of the output to be produced by render
(e.g. to
customize the preview experience).
A named list with a name
value containing the format
name and an options
value that is a list containing all the options
for the format and their values. An option's default value will be returned
if the option isn't set explicitly in the document.
Create (and optionally edit) a draft of an R Markdown document based on a template.
draft(file, template, package = NULL, create_dir = "default", edit = TRUE)
draft(file, template, package = NULL, create_dir = "default", edit = TRUE)
file |
File name for the draft |
template |
Template to use as the basis for the draft. This is either
the full path to a template directory or the name of a template directory
within the |
package |
(Optional) Name of package where the template is located. |
create_dir |
|
edit |
|
The draft
function creates new R Markdown documents based on
templates that are either located on the filesystem or within an R package.
The template and its supporting files will be copied to the location
specified by file
.
The file name of the new document (invisibly).
An R Markdown template consists of a directory that contains a description of the template, a skeleton Rmd file used as the basis for new documents, and optionally additional supporting files that are provided along with the skeleton (e.g. a logo graphic).
If the template directory is contained within a package then it should be
located at inst/rmarkdown/templates
. For example, a package named
pubtools that wanted to provide a template named
quarterly_report
would need to provide the following files within
the pubtools/inst/rmarkdown/templates
directory:
quarterly_report/template.yaml
quarterly_report/skeleton/skeleton.Rmd
The template.yaml
file should include a name
field. If you
want to ensure that a new directory is always created for a given template,
then you can add the create_dir
field to the template.yaml
file. For example:
create_dir: true
The skeleton/skeleton.Rmd
file should include the initial contents
you want for files created from this template. Additional files can be
added to the skeleton
directory, for example:
skeleton/logo.png
These files will automatically be copied to the directory containing the new R Markdown draft.
## Not run: rmarkdown::draft("Q4Report.Rmd", template="/opt/rmd/templates/quarterly_report") rmarkdown::draft("Q4Report.Rmd", template="quarterly_report", package="pubtools") ## End(Not run)
## Not run: rmarkdown::draft("Q4Report.Rmd", template="/opt/rmd/templates/quarterly_report") rmarkdown::draft("Q4Report.Rmd", template="quarterly_report", package="pubtools") ## End(Not run)
Given an R Markdown document or HTML file, attempt to determine the set of additional files needed in order to render and display the document.
find_external_resources(input_file, encoding = "UTF-8")
find_external_resources(input_file, encoding = "UTF-8")
input_file |
path to the R Markdown document or HTML file to process |
encoding |
Ignored. The encoding is always assumed to be UTF-8. |
This routine applies heuristics in order to scan a document for possible resource references.
In R Markdown documents, it looks for references to files implicitly
referenced in Markdown (e.g. ![alt](img.png)
), in the document's
YAML header, in raw HTML chunks, and as quoted strings in R code chunks
(e.g. read.csv("data.csv")
).
Resources specified explicitly in the YAML header for R Markdown
documents are also returned. To specify resources in YAML, use the
resource_files
key:
--- title: My Document author: My Name resource_files: - data/mydata.csv - images/figure.png ---
Each item in the resource_files
list can refer to:
A single file, such as images/figure.png
, or
A directory, such as resources/data
, in which case all of the
directory's content will be recursively included, or
A wildcard pattern, such as data/*.csv
, in which case all of
the files matching the pattern will be included. No recursion is done in
this case.
In HTML files (and raw HTML chunks in R Markdown documents), this routine
searches for resources specified in common tag attributes, such as
<img src="...">
, <link href="...">
, etc.
In all cases, only resources that exist on disk and are contained in the document's directory (or a child thereof) are returned.
A data frame with the following columns:
The relative path from the document to the resource
Whether the resource was specified explicitly
(TRUE
) or discovered implicitly (FALSE
)
Whether the resource is needed to display a Web page rendered from the document
pandoc
executableSearches for the pandoc
executable in a few places and use the
highest version found, unless a specific version is requested.
find_pandoc(cache = TRUE, dir = NULL, version = NULL)
find_pandoc(cache = TRUE, dir = NULL, version = NULL)
cache |
Whether to search for |
dir |
A character vector of potential directory paths under which
|
version |
The version of Pandoc to look for (e.g., |
A list containing the directory and version of Pandoc (if found).
Usually you do not need to install Pandoc if you use the RStudio IDE,
because the IDE has bundled a version of Pandoc. If you have installed a
version of Pandoc by yourself and want to use this version instead, you may
use the dir
argument of this function.
rmarkdown::find_pandoc() rmarkdown::find_pandoc(dir = '~/Downloads/Pandoc') rmarkdown::find_pandoc(version = '2.7.3')
rmarkdown::find_pandoc() rmarkdown::find_pandoc(dir = '~/Downloads/Pandoc') rmarkdown::find_pandoc(version = '2.7.3')
Format for converting from R Markdown to GitHub Flavored Markdown.
github_document( toc = FALSE, toc_depth = 3, number_sections = FALSE, math_method = "default", preserve_yaml = FALSE, fig_width = 7, fig_height = 5, dev = "png", df_print = "default", includes = NULL, md_extensions = NULL, hard_line_breaks = TRUE, pandoc_args = NULL, html_preview = TRUE, keep_html = FALSE )
github_document( toc = FALSE, toc_depth = 3, number_sections = FALSE, math_method = "default", preserve_yaml = FALSE, fig_width = 7, fig_height = 5, dev = "png", df_print = "default", includes = NULL, md_extensions = NULL, hard_line_breaks = TRUE, pandoc_args = NULL, html_preview = TRUE, keep_html = FALSE )
toc |
|
toc_depth |
Depth of headers to include in table of contents |
number_sections |
|
math_method |
|
preserve_yaml |
Preserve YAML front matter in final document. |
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
dev |
Graphics device to use for figure output (defaults to png) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
includes |
Named list of additional content to include within the
document (typically created using the |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
hard_line_breaks |
|
pandoc_args |
Additional command line options to pass to pandoc |
html_preview |
|
keep_html |
|
See the online documentation for additional details on using the github_document()
format.
R Markdown output format to pass to render()
Default behavior is to keep any inline equation using $
and any block
equation using $$
in the resulting markdown as Github will process those
using Mathjax. This feature is only available with Pandoc 2.10.1 and above
When using "webtex"
, PNG images with a white background are used by default so
that it shows correctly on Github on both light and dark theme. You can
choose to only output SVG for better quality by changing the URL used:
output: github_document: math_method: engine: webtex url: https://latex.codecogs.com/svg.image?
Background or fonts color cannot be changed for now and your equation may not be visible on dark theme.
Using "webtex"
will be the default with Pandoc 2.0.4 until Pandoc 2.10. Before 2.0.4, Github document output does not support math.
Format for converting from R Markdown to an HTML document.
html_document( toc = FALSE, toc_depth = 3, toc_float = FALSE, number_sections = FALSE, anchor_sections = FALSE, section_divs = TRUE, fig_width = 7, fig_height = 5, fig_retina = 2, fig_caption = TRUE, dev = "png", df_print = "default", code_folding = c("none", "show", "hide"), code_download = FALSE, self_contained = TRUE, theme = "default", highlight = "default", highlight_downlit = FALSE, math_method = "default", mathjax = "default", template = "default", extra_dependencies = NULL, css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, md_extensions = NULL, pandoc_args = NULL, ... )
html_document( toc = FALSE, toc_depth = 3, toc_float = FALSE, number_sections = FALSE, anchor_sections = FALSE, section_divs = TRUE, fig_width = 7, fig_height = 5, fig_retina = 2, fig_caption = TRUE, dev = "png", df_print = "default", code_folding = c("none", "show", "hide"), code_download = FALSE, self_contained = TRUE, theme = "default", highlight = "default", highlight_downlit = FALSE, math_method = "default", mathjax = "default", template = "default", extra_dependencies = NULL, css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, md_extensions = NULL, pandoc_args = NULL, ... )
toc |
|
toc_depth |
Depth of headers to include in table of contents |
toc_float |
|
number_sections |
|
anchor_sections |
|
section_divs |
Wrap sections in |
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays (defaults to 2, which
currently works for all widely used retina displays). Set to |
fig_caption |
|
dev |
Graphics device to use for figure output (defaults to png) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
code_folding |
Enable document readers to toggle the display of R code
chunks. Specify |
code_download |
Embed the Rmd source code within the document and provide a link that can be used by readers to download the code. |
self_contained |
Produce a standalone HTML file with no external dependencies, using data: URIs to incorporate the contents of linked scripts, stylesheets, images, and videos. Note that even for self contained documents MathJax is still loaded externally (this is necessary because of its size). |
theme |
One of the following:
|
highlight |
Syntax highlight engine and style. See the Highlighting section below for details. "default" (and "textmate") will use highlightjs as syntax highlighting engine instead of Pandoc. Any other value will be passed as Pandoc's highlighting style. Pandoc's built-in styles include "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a path to a ‘.theme’ to use a custom Pandoc style. Note that custom theme requires Pandoc 2.0+. Pass |
highlight_downlit |
Only Pandoc color schemes are supported with this engine. With
|
math_method |
Math rendering engine to use. This will define the math method to use with Pandoc.
For example, output: html_document: math_method: engine: katex url: https://cdn.jsdelivr.net/npm/[email protected]/dist See Pandoc's Manual about Math in HTML for the details about Pandoc supported methods. Using |
mathjax |
Include mathjax. The "default" option uses an https URL from a
MathJax CDN. The "local" option uses a local version of MathJax (which is
copied into the output directory). You can pass an alternate URL or pass
|
template |
Pandoc template to use for rendering. Pass "default" to use
the rmarkdown package default template; pass |
extra_dependencies |
Extra dependencies as a list of the
|
css |
CSS and/or Sass files to include. Files with an extension of .sass
or .scss are compiled to CSS via |
includes |
Named list of additional content to include within the
document (typically created using the |
keep_md |
Keep the markdown file generated by knitting. |
lib_dir |
Directory to copy dependent HTML libraries (e.g. jquery,
bootstrap, etc.) into. By default this will be the name of the document with
|
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
... |
Additional function arguments to pass to the base R Markdown HTML
output formatter |
See the online
documentation for additional details on using the html_document
format.
R Markdown documents can have optional metadata that is used to generate a document header that includes the title, author, and date. For more details see the documentation on R Markdown metadata.
R Markdown documents also support citations. You can find more information on the markdown syntax for citations in the Bibliographies and Citations article in the online documentation.
R Markdown output format to pass to render
There are three highlighting engines available to HTML documents:
It does highlighting in the browser, using javascript It
can only be used with the default template (i.e template = "default"
)
and it has two styles ("default" and "textmate"). When activated, it adds
two additional dependencies to the output file: a JS script and a CSS file.
For now, this is the default engine for the default template - this could
change in the future.
Pandoc's built-in highlighting.engine works with any template,
default or custom, and style can be chosen among the built-in ones ("tango",
"pygments", "kate", "monochrome", "espresso", "zenburn", "haddock" and
"breezedark") or a path to a custom theme ".theme" file (see Details in the
Pandoc Manual).
rmarkdown includes two custom themes to select with highlight
parameter:
"arrow", an accessible style using colors optimized for accessibility and color contrast
"rstudio", a color scheme close to RStudio's default highlighting and highglightjs's textmate.
Custom themes are only available for Pandoc 2.0 and above.
downlit is an R package that
provides a syntax highlighting engine in R. It will also do automatic
linking of R code (requires internet connectivity). It is activated only if
highlight_downlit = TRUE
and only affects R code, leaving
highlighting for other languages unchanged. The default color scheme is
the accessible theme "arrow".
It requires some CSS in the template to correctly style links. This is included in the default template, but if you want to use with a custom template, you will need to add this to your template:
$if(highlight-downlit)$ <style type="text/css"> code a:any-link { color: inherit; /* use colour from syntax highlighting */ text-decoration: underline; text-decoration-color: #ccc; } </style> $endif$
This will be the default to activate anchor sections link on header
output: html_document: anchor_sections: TRUE
There are currently two options to modify the default behavior
style
Select a predefined visual style:
style = "dash"
, the default, uses ‘#’, a minimalist choice that evokes the id selector from HTML and CSS.
style = "symbol"
will use a link symbol (🔗︎)
style = "icon"
will use an svg icon. ()
You can also customize using a css rule in your document. For example, to get a pictogram (🔗):
a.anchor-section::before { content: '\\01F517'; }
About how to apply custom CSS in R Markdown document, see https://bookdown.org/yihui/rmarkdown-cookbook/html-css.html
depth
Select the maximum header level to add the anchor link to. For example, this yaml will use the symbol style and only with level 1 and 2 headings:
output: html_document: anchor_sections: style: icon depth: 2
If omitted, anchor will be added to all headers (equivalent of
depth=6
). You can also set anchors manually with depth = 0
using this syntax
# my header {.hasAnchor}
Using anchor sections will add some CSS to your document output for the
styling, and a JS script if section_divs = TRUE
. The anchor link itself
is added using a Lua filter, and hence requires Pandoc 2.0+
If you have a set of html documents which you'd like to provide a common global navigation bar for, you can include a "_navbar.yml" or "_navbar.html" file within the same directory as your html document and it will automatically be included at the top of the document.
The "_navbar.yml" file includes title
, type
, left
, and
right
fields (to define menu items for the left and right of the navbar
respectively). Menu items include title
and href
fields. For example:
title: "My Website" type: default left: - text: "Home" href: index.html - text: "Other" href: other.html right: - text: GitHub href: https://github.com
The type
field is optional and can take the value "default" or "inverse" (which
provides a different color scheme for the navigation bar).
Alternatively, you can include a "_navbar.html" file which is a full HTML definition of a bootstrap navigation bar. For a simple example of including a navigation bar see https://github.com/rstudio/rmarkdown-website/blob/master/_navbar.html. For additional documentation on creating Bootstrap navigation bars see https://getbootstrap.com/docs/4.5/components/navbar/.
You may specify a list of options for the toc_float
parameter which
control the behavior of the floating table of contents. Options include:
collapsed
(defaults to TRUE
) controls whether
the table of contents appears with only the top-level (H2) headers. When
collapsed the table of contents is automatically expanded inline when
necessary.
smooth_scroll
(defaults to TRUE
) controls
whether page scrolls are animated when table of contents items are navigated
to via mouse clicks.
print
(defaults to TRUE
) controls
whether the table of contents appears when user prints out the HTML page.
Code blocks become foldable by specifying "show" or "hide" to the
code_folding
parameter. The state can be toggled individually on
browsers. The document-wide toggle button is also provided for
html_document
and some of its extensions such as
html_notebook
. Note that this feature applies not only to source
codes of chunks, but also markdown code blocks.
Supported languages are R, Python, Bash, SQL, C++, Stan, and Julia. To
support code blocks with other languages, add foldable
class to them
(i.e., class.source = "foldable"
as a chunk option).
The default initial state of code folding respects the value given to the
code_folding
parameter. To override the behavior individually, add
fold-none
to disable, fold-hide
to initially hide,
fold-show
to initially show.
You can organize content using tabs by applying the .tabset
class
attribute to headers within a document. This will cause all sub-headers of
the header with the .tabset
attribute to appear within tabs rather
than as standalone sections. For example:
## Quarterly Results {.tabset} ### By Product ### By Region
With html_document()
, you can also specify two additional attributes to
control the appearance and behavior of the tabs. The .tabset-fade
attributes causes the tabs to fade in and out when switching. The
.tabset-pills
attribute causes the visual appearance of the tabs to
be "pill" rather than traditional tabs. For example:
## Quarterly Results {.tabset .tabset-fade .tabset-pills}
If tabbed sections relies on html_dependency_tabset()
, for example by
html_vignette()
, these two attributes are not supported.
You can provide a custom HTML template to be used for rendering. The syntax
for templates is described in the
pandoc documentation. You can also use
the basic pandoc template by passing template = NULL
.
Note however that if you choose not to use the "default" HTML template then several aspects of HTML document rendering will behave differently:
The theme
parameter does not work (you can still provide styles
using the css
parameter).
For the highlight
parameter, the default highlighting engine
will resolve to Pandoc instead of highlightjs and highlighting style will default to
"pygments". "textmate" style is not available as related to highlightjs
The toc_float
parameter will not work.
The code_folding
parameter will not work.
Tabbed sections (as described above) will not work.
Navigation bars (as described above) will not work.
MathJax will not work if self_contained
is TRUE
(these
two options can't be used together in normal pandoc templates).
Due to the above restrictions, you might consider using the includes
parameter as an alternative to providing a fully custom template.
## Not run: library(rmarkdown) render("input.Rmd", html_document()) render("input.Rmd", html_document(toc = TRUE)) ## End(Not run)
## Not run: library(rmarkdown) render("input.Rmd", html_document()) render("input.Rmd", html_document(toc = TRUE)) ## End(Not run)
Creates an HTML base output format suitable for passing as the
base_format
argument of the output_format
function.
html_document_base( theme = NULL, self_contained = TRUE, lib_dir = NULL, math_method = "default", mathjax = "default", pandoc_args = NULL, template = "default", dependency_resolver = NULL, copy_resources = FALSE, extra_dependencies = NULL, css = NULL, bootstrap_compatible = FALSE, ... )
html_document_base( theme = NULL, self_contained = TRUE, lib_dir = NULL, math_method = "default", mathjax = "default", pandoc_args = NULL, template = "default", dependency_resolver = NULL, copy_resources = FALSE, extra_dependencies = NULL, css = NULL, bootstrap_compatible = FALSE, ... )
theme |
One of the following:
|
self_contained |
Produce a standalone HTML file with no external dependencies, using data: URIs to incorporate the contents of linked scripts, stylesheets, images, and videos. Note that even for self contained documents MathJax is still loaded externally (this is necessary because of its size). |
lib_dir |
Directory to copy dependent HTML libraries (e.g. jquery,
bootstrap, etc.) into. By default this will be the name of the document with
|
math_method |
Math rendering engine to use. This will define the math method to use with Pandoc.
For example, output: html_document: math_method: engine: katex url: https://cdn.jsdelivr.net/npm/[email protected]/dist See Pandoc's Manual about Math in HTML for the details about Pandoc supported methods. Using |
mathjax |
Include mathjax. The "default" option uses an https URL from a
MathJax CDN. The "local" option uses a local version of MathJax (which is
copied into the output directory). You can pass an alternate URL or pass
|
pandoc_args |
Additional command line options to pass to pandoc |
template |
Pandoc template to use for rendering. Pass "default" to use
the rmarkdown package default template; pass |
dependency_resolver |
A dependency resolver |
copy_resources |
Copy resources |
extra_dependencies |
Extra dependencies as a list of the
|
css |
CSS and/or Sass files to include. Files with an extension of .sass
or .scss are compiled to CSS via |
bootstrap_compatible |
Bootstrap compatible |
... |
Ignored |
HTML base output format.
An html fragment is suitable for inclusion into an external html page. See
html_document
for full details - this is a minor variation that
assumes you will include the output into an existing document (e.g. a blog
post).
html_fragment( number_sections = FALSE, section_divs = TRUE, fig_width = 7, fig_height = 5, fig_retina = 2, fig_caption = TRUE, dev = "png", df_print = "default", mathjax = TRUE, includes = NULL, keep_md = FALSE, md_extensions = NULL, pandoc_args = NULL, ... )
html_fragment( number_sections = FALSE, section_divs = TRUE, fig_width = 7, fig_height = 5, fig_retina = 2, fig_caption = TRUE, dev = "png", df_print = "default", mathjax = TRUE, includes = NULL, keep_md = FALSE, md_extensions = NULL, pandoc_args = NULL, ... )
number_sections |
|
section_divs |
Wrap sections in |
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays (defaults to 2, which
currently works for all widely used retina displays). Set to |
fig_caption |
|
dev |
Graphics device to use for figure output (defaults to png) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
mathjax |
|
includes |
Named list of additional content to include within the
document (typically created using the |
keep_md |
Keep the markdown file generated by knitting. |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
... |
Additional arguments passed to |
See the online
documentation for additional details on using the html_fragment
format.
R Markdown output format to pass to render
Format for converting from R Markdown to an HTML notebook.
html_notebook( toc = FALSE, toc_depth = 3, toc_float = FALSE, number_sections = FALSE, fig_width = 7, fig_height = 5, fig_retina = 2, fig_caption = TRUE, code_folding = "show", theme = "default", highlight = "textmate", highlight_downlit = FALSE, math_method = "default", mathjax = "default", extra_dependencies = NULL, css = NULL, includes = NULL, md_extensions = NULL, pandoc_args = NULL, output_source = NULL, self_contained = TRUE, ... )
html_notebook( toc = FALSE, toc_depth = 3, toc_float = FALSE, number_sections = FALSE, fig_width = 7, fig_height = 5, fig_retina = 2, fig_caption = TRUE, code_folding = "show", theme = "default", highlight = "textmate", highlight_downlit = FALSE, math_method = "default", mathjax = "default", extra_dependencies = NULL, css = NULL, includes = NULL, md_extensions = NULL, pandoc_args = NULL, output_source = NULL, self_contained = TRUE, ... )
toc |
|
toc_depth |
Depth of headers to include in table of contents |
toc_float |
|
number_sections |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays (defaults to 2, which
currently works for all widely used retina displays). Set to |
fig_caption |
|
code_folding |
Enable document readers to toggle the display of R code
chunks. Specify |
theme |
One of the following:
|
highlight |
Syntax highlight engine and style. See the Highlighting section below for details. "default" (and "textmate") will use highlightjs as syntax highlighting engine instead of Pandoc. Any other value will be passed as Pandoc's highlighting style. Pandoc's built-in styles include "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a path to a ‘.theme’ to use a custom Pandoc style. Note that custom theme requires Pandoc 2.0+. Pass |
highlight_downlit |
Only Pandoc color schemes are supported with this engine. With
|
math_method |
Math rendering engine to use. This will define the math method to use with Pandoc.
For example, output: html_document: math_method: engine: katex url: https://cdn.jsdelivr.net/npm/[email protected]/dist See Pandoc's Manual about Math in HTML for the details about Pandoc supported methods. Using |
mathjax |
Include mathjax. The "default" option uses an https URL from a
MathJax CDN. The "local" option uses a local version of MathJax (which is
copied into the output directory). You can pass an alternate URL or pass
|
extra_dependencies |
Extra dependencies as a list of the
|
css |
CSS and/or Sass files to include. Files with an extension of .sass
or .scss are compiled to CSS via |
includes |
Named list of additional content to include within the
document (typically created using the |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
output_source |
Define an output source for R chunks (ie,
outputs to use instead of those produced by evaluating the
underlying R code). See |
self_contained |
Produce a standalone HTML file with no external
dependencies. Defaults to |
... |
Additional function arguments to pass to the base R Markdown HTML
output formatter |
See the online
documentation for additional details on using the html_notebook
format.
A structured helper for the construction of metadata used by the
R Notebook output functions. See html_notebook_output
for
more details.
html_notebook_metadata(iframe = TRUE)
html_notebook_metadata(iframe = TRUE)
iframe |
Boolean; should output be shown in an |
Utilities for generating output for the html_notebook
format,
through the output_source
function attached to a
output_format
.
html_notebook_output_html(html, meta = NULL) html_notebook_output_img( path = NULL, bytes = NULL, attributes = NULL, meta = NULL, format = c("png", "jpeg") ) html_notebook_output_png( path = NULL, bytes = NULL, attributes = NULL, meta = NULL, format = c("png", "jpeg") ) html_notebook_output_code(code, attributes = list(class = "r"), meta = NULL)
html_notebook_output_html(html, meta = NULL) html_notebook_output_img( path = NULL, bytes = NULL, attributes = NULL, meta = NULL, format = c("png", "jpeg") ) html_notebook_output_png( path = NULL, bytes = NULL, attributes = NULL, meta = NULL, format = c("png", "jpeg") ) html_notebook_output_code(code, attributes = list(class = "r"), meta = NULL)
html |
Arbitrary HTML content to insert. |
meta |
An R list of arbitrary meta-data. The data will be converted to JSON, base64-encoded, and injected into the header comment. |
path |
A path to a file. For functions accepting both |
bytes |
The bytewise representation of content. |
attributes |
A named R list of HTML attributes. These will be escaped and inserted into the generated HTML as appropriate. |
format |
The image format; one of |
code |
Source code. |
See the online
documentation for additional details on using the html_notebook
format.
A HTML vignette is a lightweight alternative to html_document()
suitable for inclusion in packages to be released to CRAN. It reduces the
size of a basic vignette from 100k to around 10k.
html_vignette( fig_width = 3, fig_height = 3, dev = "png", df_print = "default", css = NULL, highlight = "pygments", keep_md = FALSE, readme = FALSE, self_contained = TRUE, tabset = FALSE, code_folding = c("none", "show", "hide"), extra_dependencies = NULL, pandoc_args = NULL, ... )
html_vignette( fig_width = 3, fig_height = 3, dev = "png", df_print = "default", css = NULL, highlight = "pygments", keep_md = FALSE, readme = FALSE, self_contained = TRUE, tabset = FALSE, code_folding = c("none", "show", "hide"), extra_dependencies = NULL, pandoc_args = NULL, ... )
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
dev |
Graphics device to use for figure output (defaults to png) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
css |
One or more css files to include. |
highlight , ...
|
Additional arguments passed to
|
keep_md |
Keep the markdown file generated by knitting. |
readme |
Use this vignette as the package README.md file (i.e. render it as README.md to the package root). Note that if there are image files within your vignette you should be sure to add ‘README_files’ to ‘.Rbuildignore’. |
self_contained |
Produce a standalone HTML file with no external dependencies, using data: URIs to incorporate the contents of linked scripts, stylesheets, images, and videos. Note that even for self contained documents MathJax is still loaded externally (this is necessary because of its size). |
tabset |
Opt-in tabbed-sections feature inspired by |
code_folding |
Enable document readers to toggle the display of R code
chunks. Specify |
extra_dependencies |
Extra dependencies as a list of the
|
pandoc_args |
Additional command line options to pass to pandoc |
Compared to html_document()
, it:
never uses retina figures
never uses a theme
has a smaller default figure size
uses a custom css stylesheet
See the online documentation
for additional details on using the html_vignette()
format.
R Markdown output format to pass to render()
You can organize content using tabs by applying the .tabset
class
attribute to headers within a document. This will cause all sub-headers of
the header with the .tabset
attribute to appear within tabs rather
than as standalone sections. For example:
## Quarterly Results {.tabset} ### By Product ### By Region
With html_document()
, you can also specify two additional attributes to
control the appearance and behavior of the tabs. The .tabset-fade
attributes causes the tabs to fade in and out when switching. The
.tabset-pills
attribute causes the visual appearance of the tabs to
be "pill" rather than traditional tabs. For example:
## Quarterly Results {.tabset .tabset-fade .tabset-pills}
If tabbed sections relies on html_dependency_tabset()
, for example by
html_vignette()
, these two attributes are not supported.
Code blocks become foldable by specifying "show" or "hide" to the
code_folding
parameter. The state can be toggled individually on
browsers. The document-wide toggle button is also provided for
html_document
and some of its extensions such as
html_notebook
. Note that this feature applies not only to source
codes of chunks, but also markdown code blocks.
Supported languages are R, Python, Bash, SQL, C++, Stan, and Julia. To
support code blocks with other languages, add foldable
class to them
(i.e., class.source = "foldable"
as a chunk option).
The default initial state of code folding respects the value given to the
code_folding
parameter. To override the behavior individually, add
fold-none
to disable, fold-hide
to initially hide,
fold-show
to initially show.
These functions provide common HTML dependencies (e.g. jquery, bootstrap) for re-use by other R Markdown formats.
html_dependency_jquery() html_dependency_jqueryui() html_dependency_bootstrap(theme) html_dependency_tocify() html_dependency_font_awesome() html_dependency_ionicons() html_dependency_pagedtable() html_dependency_highlightjs(highlight) html_dependency_tabset() html_dependency_codefolding_lua()
html_dependency_jquery() html_dependency_jqueryui() html_dependency_bootstrap(theme) html_dependency_tocify() html_dependency_font_awesome() html_dependency_ionicons() html_dependency_pagedtable() html_dependency_highlightjs(highlight) html_dependency_tabset() html_dependency_codefolding_lua()
theme |
One of the following:
|
highlight |
Highlighter to use |
Specify additional content to be included within an output document.
includes(in_header = NULL, before_body = NULL, after_body = NULL) includes_to_pandoc_args(includes, filter = identity)
includes(in_header = NULL, before_body = NULL, after_body = NULL) includes_to_pandoc_args(includes, filter = identity)
in_header |
One or more files with content to be included in the header of the document. |
before_body |
One or more files with content to be included before the document body. |
after_body |
One or more files with content to be included after the document body. |
includes |
Includes to convert to pandoc args. |
filter |
Filter to pre-process includes with. |
Non-absolute paths for resources referenced from the
in_header
, before_body
, and after_body
parameters are resolved relative to the directory of the input document.
Includes list or pandoc args
## Not run: library(rmarkdown) html_document(includes = includes(before_body = "header.htm")) pdf_document(includes = includes(after_body = "footer.tex")) ## End(Not run)
## Not run: library(rmarkdown) html_document(includes = includes(before_body = "header.htm")) pdf_document(includes = includes(after_body = "footer.tex")) ## End(Not run)
Format for converting from R Markdown to an ioslides presentation.
ioslides_presentation( number_sections = FALSE, logo = NULL, slide_level = 2, incremental = FALSE, fig_width = 7.5, fig_height = 4.5, fig_retina = 2, fig_caption = TRUE, dev = "png", df_print = "default", smart = TRUE, self_contained = TRUE, widescreen = FALSE, smaller = FALSE, transition = "default", math_method = "mathjax", mathjax = "default", analytics = NULL, template = NULL, css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, md_extensions = NULL, pandoc_args = NULL, extra_dependencies = NULL, ... )
ioslides_presentation( number_sections = FALSE, logo = NULL, slide_level = 2, incremental = FALSE, fig_width = 7.5, fig_height = 4.5, fig_retina = 2, fig_caption = TRUE, dev = "png", df_print = "default", smart = TRUE, self_contained = TRUE, widescreen = FALSE, smaller = FALSE, transition = "default", math_method = "mathjax", mathjax = "default", analytics = NULL, template = NULL, css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, md_extensions = NULL, pandoc_args = NULL, extra_dependencies = NULL, ... )
number_sections |
|
logo |
Path to file that includes a logo for use in the presentation (should be square and at least 128x128). |
slide_level |
Header level to consider as slide separator (Defaults to header 2). |
incremental |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays (defaults to 2, which
currently works for all widely used retina displays). Set to |
fig_caption |
|
dev |
Graphics device to use for figure output (defaults to png) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
smart |
Produce typographically correct output, converting straight
quotes to curly quotes, |
self_contained |
Produce a standalone HTML file with no external dependencies, using data: URIs to incorporate the contents of linked scripts, stylesheets, images, and videos. Note that even for self contained documents MathJax is still loaded externally (this is necessary because of its size). |
widescreen |
Display presentation with wider dimensions. |
smaller |
Use smaller text on all slides. You can also enable this for
individual slides by adding the |
transition |
Speed of slide transitions. This can be "default", "slower", "faster", or a numeric value with a number of seconds (e.g. 0.5). |
math_method |
Math rendering engine to use. This will define the math method to use with Pandoc.
For example, output: html_document: math_method: engine: katex url: https://cdn.jsdelivr.net/npm/[email protected]/dist See Pandoc's Manual about Math in HTML for the details about Pandoc supported methods. Using |
mathjax |
Include mathjax. The "default" option uses an https URL from a
MathJax CDN. The "local" option uses a local version of MathJax (which is
copied into the output directory). You can pass an alternate URL or pass
|
analytics |
A Google analytics property ID. |
template |
Pandoc template to use for rendering. Pass "default" to use
the rmarkdown package default template; pass |
css |
One or more css files to include. |
includes |
Named list of additional content to include within the
document (typically created using the |
keep_md |
Keep the markdown file generated by knitting. |
lib_dir |
Directory to copy dependent HTML libraries (e.g. jquery,
bootstrap, etc.) into. By default this will be the name of the document with
|
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
extra_dependencies |
Extra dependencies as a list of the
|
... |
Additional function arguments to pass to the base R Markdown HTML
output formatter |
See the online documentation for additional details on using the
ioslides_presentation
format.
Note that, if a before_body
include is specified in includes
,
then it will replace the standard title slide entirely.
Regarding previewing slide in RStudio IDE, ioslides_presentation()
will
always open preview in a new Window and the RStudio IDE configuration "Open in Viewer
Pane" will have no effect for this format.
R Markdown output format to pass to render()
.
You can create a slide show broken up into sections by using the # and ##
heading tags (you can also create a new slide without a header using a
horizontal rule (----------
). For example here's a simple slide show:
--- title: "Habits" author: John Doe date: March 22, 2005 output: ioslides_presentation --- # In the morning ## Getting up - Turn off alarm - Get out of bed ## Breakfast - Eat eggs - Drink coffee # In the evening ## Dinner - Eat spaghetti - Drink wine ---------- ![picture of spaghetti](images/spaghetti.jpg) ## Going to sleep - Get in bed - Count sheep
You can add a subtitle to a slide or section by including text after the pipe (|) character. For example:
## Getting up | What I like to do first thing
The following single character keyboard shortcuts enable alternate display modes:
'f'
enable fullscreen mode
'w'
toggle widescreen mode
'o'
enable overview mode
'h'
enable code highlight mode
'p'
show presenter notes
Pressing Esc
exits all of these modes. See the sections below on
Code Highlighting and Presenter Mode for additional
detail on those modes.
You can render bullets incrementally by adding the incremental
option:
--- output: ioslides_presentation: incremental: true ---
If you want to render bullets incrementally for some slides but not others you can use this syntax:
> - Eat eggs > - Drink coffee
You can display the presentation using a wider form factor using the
widescreen
option. You can specify that smaller text be used with
the smaller
option. For example:
--- output: ioslides_presentation: widescreen: true smaller: true ---
You can also enable the smaller
option on a slide-by-slide basis
by adding the .smaller
attribute to the slide header:
## Getting up {.smaller}
You can add a logo to the presentation using the logo
option (the
logo should be square and at least 128x128). For example:
--- output: ioslides_presentation: logo: logo.png ---
A 128x128 version of the logo graphic will be added to the title slide and an icon version of the logo will be included in the bottom-left footer of each slide.
Slides can also have a .build
attribute that indicate that their
content should be displayed incrementally. For example:
## Getting up {.build}
Slide attributes can be combined if you need to specify more than one, for example:
## Getting up {.smaller .build}
It's possible to select subsets of code for additional emphasis by adding a special "highlight" comment around the code. For example:
### <b> x <- 10 y <- x * 2 ### </b>
The highlighted region will be displayed with a bold font. When you want to
help the audience focus exclusively on the highlighted region press the
'h'
key and the rest of the code will fade away.
The ioslides template has an attractive default style for tables so you shouldn't hesitate to add tables for presenting more complex sets of information. Pandoc markdown supports several syntaxes for defining tables which are described in the pandoc online documentation.
You can center content on a slide by adding the .flexbox
and .vcenter
attributes to the slide title. For example:
## Dinner {.flexbox .vcenter}
You can horizontally center content by enclosing it in a div
tag
with class centered
. For example:
<div class="centered"> This text is centered. </div>
You can do a two-column layout using the columns-2
class.
For example:
<div class="columns-2"> ![Image](image.png) - Bullet 1 - Bullet 2 - Bullet 3 </div>
Note that content will flow across the columns so if you want to have an image on one side and text on the other you should make sure that the image has sufficient height to force the text to the other side of the slide.
You can color content using base color classes red, blue, green, yellow, and gray (or variations of them e.g. red2, red3, blue2, blue3, etc.). For example:
<div class="red2"> This text is red </div>
A separate presenter window can also be opened (ideal for when you are
presenting on one screen but have another screen that's private to you).
The window stays in sync with the main presentation window and also
shows presenter notes and a thumbnail of the next slide. To enable
presenter mode add ?presentme=true
to the URL of the presentation,
for example:
mypresentation.html?presentme=true
The presenter mode window will open and will always re-open with the presentation until it's disabled with:
mypresentation.html?presentme=false
To add presenter notes to a slide you include it within a "notes"
div
. For example:
<div class="notes"> This is my *note*. - It can contain markdown - like this list </div>
You can print an ioslides presentation from within browsers that have good support for print CSS (i.e. as of this writing Google Chrome has the best support). Printing maintains most of the visual styles of the HTML version of the presentation.
To create a PDF version of a presentation you can use Print to PDF from Google Chrome.
Run a shiny application asking for parameter configuration for the given document.
knit_params_ask( file = NULL, input_lines = NULL, params = NULL, shiny_args = NULL, save_caption = "Save", encoding = "UTF-8" )
knit_params_ask( file = NULL, input_lines = NULL, params = NULL, shiny_args = NULL, save_caption = "Save", encoding = "UTF-8" )
file |
Path to the R Markdown document with configurable parameters. |
input_lines |
Content of the R Markdown document. If |
params |
A named list of optional parameter overrides used in place of the document defaults. |
shiny_args |
Additional arguments to |
save_caption |
Caption to use use for button that saves/confirms parameters. |
encoding |
Ignored. The encoding is always assumed to be UTF-8. |
named list with overridden parameter names and value.
Define the knitr options for an R Markdown output format.
knitr_options( opts_knit = NULL, opts_chunk = NULL, knit_hooks = NULL, opts_hooks = NULL, opts_template = NULL )
knitr_options( opts_knit = NULL, opts_chunk = NULL, knit_hooks = NULL, opts_hooks = NULL, opts_template = NULL )
opts_knit |
List of package level knitr options (see
|
opts_chunk |
List of chunk level knitr options (see
|
knit_hooks |
List of hooks for R code chunks, inline R code, and output
(see |
opts_hooks |
List of hooks for code chunk options
(see |
opts_template |
List of templates for chunk level knitr options (see
|
An list that can be passed as the knitr
argument
of the output_format
function.
Define knitr options for an R Markdown output format that creates HTML output.
knitr_options_html(fig_width, fig_height, fig_retina, keep_md, dev = "png")
knitr_options_html(fig_width, fig_height, fig_retina, keep_md, dev = "png")
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays (defaults to 2, which
currently works for all widely used retina displays). Set to |
keep_md |
Keep the markdown file generated by knitting. |
dev |
Graphics device to use for figure output (defaults to png) |
An list that can be passed as the knitr
argument of the
output_format
function.
Define knitr options for an R Markdown output format that creates PDF output.
knitr_options_pdf(fig_width, fig_height, fig_crop, dev = "pdf")
knitr_options_pdf(fig_width, fig_height, fig_crop, dev = "pdf")
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_crop |
Whether to crop PDF figures with the command
|
dev |
Graphics device to use for figure output (defaults to png) |
An list that can be passed as the knitr
argument of the
output_format
function.
Define a LaTeX package dependency
latex_dependency(name, options = NULL, extra_lines = NULL)
latex_dependency(name, options = NULL, extra_lines = NULL)
name |
The LaTeX package name |
options |
The LaTeX options for the package |
extra_lines |
LaTeX code related to the package added to the preamble |
These functions provide common LaTeX dependencies (e.g. tikz) for R Markdown formats that use LaTeX.
latex_dependency_tikz(libraries, options = NULL, extra_lines = NULL)
latex_dependency_tikz(libraries, options = NULL, extra_lines = NULL)
libraries |
A character vector of tikz libraries to load |
options |
The LaTeX options for the package |
extra_lines |
LaTeX code related to the package added to the preamble |
Format for converting from R Markdown to another variant of markdown (e.g. strict markdown or github flavored markdown)
md_document( variant = "markdown_strict", preserve_yaml = FALSE, toc = FALSE, toc_depth = 3, number_sections = FALSE, standalone = FALSE, fig_width = 7, fig_height = 5, fig_retina = NULL, dev = "png", df_print = "default", includes = NULL, md_extensions = NULL, pandoc_args = NULL, ext = ".md" )
md_document( variant = "markdown_strict", preserve_yaml = FALSE, toc = FALSE, toc_depth = 3, number_sections = FALSE, standalone = FALSE, fig_width = 7, fig_height = 5, fig_retina = NULL, dev = "png", df_print = "default", includes = NULL, md_extensions = NULL, pandoc_args = NULL, ext = ".md" )
variant |
Markdown variant to produce (defaults to "markdown_strict"). Other valid values are "commonmark", "gfm", "commonmark_x", "markdown_mmd", markdown_phpextra", "markdown_github", or even "markdown" (which produces pandoc markdown). You can also compose custom markdown variants, see the pandoc online documentation for details. |
preserve_yaml |
Preserve YAML front matter in final document. |
toc |
|
toc_depth |
Depth of headers to include in table of contents |
number_sections |
|
standalone |
Set to |
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays. Defaults to
|
dev |
Graphics device to use for figure output (defaults to png) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
includes |
Named list of additional content to include within the
document (typically created using the |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
ext |
Extension of the output file (defaults to ".md"). |
See the online documentation
for additional details on using the md_document()
format.
R Markdown documents can have optional metadata that is used to generate a document header that includes the title, author, and date. For more details see the documentation on R Markdown metadata.
R Markdown output format to pass to render()
## Not run: library(rmarkdown) render("input.Rmd", md_document()) render("input.Rmd", md_document(variant = "markdown_github")) ## End(Not run)
## Not run: library(rmarkdown) render("input.Rmd", md_document()) render("input.Rmd", md_document(variant = "markdown_github")) ## End(Not run)
The object metadata
stores the YAML metadata of the current R Markdown
document as a list, which you may use in the R code chunks, e.g.
rmarkdown::metadata$title
(the title of the document),
rmarkdown::metadata$author
, and rmarkdown::metadata$foo
(if you
have a YAML field named foo
), etc.
An object of class list
of length 0.
rmarkdown::metadata
rmarkdown::metadata
Format for converting from R Markdown to an ODT document.
odt_document( number_sections = FALSE, fig_width = 5, fig_height = 4, fig_caption = TRUE, template = "default", reference_odt = "default", includes = NULL, keep_md = FALSE, md_extensions = NULL, pandoc_args = NULL )
odt_document( number_sections = FALSE, fig_width = 5, fig_height = 4, fig_caption = TRUE, template = "default", reference_odt = "default", includes = NULL, keep_md = FALSE, md_extensions = NULL, pandoc_args = NULL )
number_sections |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_caption |
|
template |
Pandoc template to use for rendering. Pass "default" to use
the rmarkdown package default template; pass |
reference_odt |
Use the specified file as a style reference in producing an odt file. For best results, the reference odt should be a modified version of an odt file produced using pandoc. Pass "default" to use the rmarkdown default styles. |
includes |
Named list of additional content to include within the
document (typically created using the |
keep_md |
Keep the markdown file generated by knitting. |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
See the online
documentation for additional details on using the odt_document
format.
R Markdown documents can have optional metadata that is used to generate a document header that includes the title, author, and date. For more details see the documentation on R Markdown metadata.
R Markdown documents also support citations. You can find more information on the markdown syntax for citations in the Bibliographies and Citations article in the online documentation.
R Markdown output format to pass to render
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", odt_document()) # specify an option for syntax highlighting render("input.Rmd", odt_document(highlight = "zenburn")) ## End(Not run)
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", odt_document()) # specify an option for syntax highlighting render("input.Rmd", odt_document(highlight = "zenburn")) ## End(Not run)
Define an R Markdown output format based on a combination of knitr and pandoc options.
output_format( knitr, pandoc, keep_md = FALSE, clean_supporting = TRUE, df_print = NULL, pre_knit = NULL, post_knit = NULL, pre_processor = NULL, intermediates_generator = NULL, post_processor = NULL, on_exit = NULL, file_scope = NULL, base_format = NULL )
output_format( knitr, pandoc, keep_md = FALSE, clean_supporting = TRUE, df_print = NULL, pre_knit = NULL, post_knit = NULL, pre_processor = NULL, intermediates_generator = NULL, post_processor = NULL, on_exit = NULL, file_scope = NULL, base_format = NULL )
knitr |
Knitr options for an output format (see
|
pandoc |
Pandoc options for an output format (see
|
keep_md |
Keep the markdown file generated by knitting. Note that if
this is |
clean_supporting |
Cleanup any supporting files after conversion see
|
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
pre_knit |
An optional function that runs before knitting which receives
the |
post_knit |
An optional function that runs after knitting which receives
the |
pre_processor |
An optional pre-processor function that receives the
|
intermediates_generator |
An optional function that receives the
original |
post_processor |
An optional post-processor function that receives the
|
on_exit |
A function to call when |
file_scope |
A function that will split markdown input to pandoc into
multiple named files. This is useful when the caller has concatenated a set
of Rmd files together (as bookdown does), and those files may need to
processed by pandoc using the |
base_format |
An optional format to extend. |
An R Markdown output format definition that can be passed to
render
.
render, knitr_options, pandoc_options
## Not run: output_format(knitr = knitr_options(opts_chunk = list(dev = 'png')), pandoc = pandoc_options(to = "html")) ## End(Not run)
## Not run: output_format(knitr = knitr_options(opts_chunk = list(dev = 'png')), pandoc = pandoc_options(to = "html")) ## End(Not run)
Define and merge a dependency such as pre/post-processors from within
chunks. The merge happens explicitly when a list of dependencies are
passed to knitr::knit_meta_add()
or implicitly when a dependency
is knitr::knit_print
ed. Defining a function that does the former is
the best way for package developers to share the dependency. On the
contrary, the latter is useful to declare a document-specific dependency.
This function shares some arguments with output_format
,
but lacks the others because dependency is resolved after post_knit
and before pre_processor
.
output_format_dependency( name, pandoc = list(), pre_processor = NULL, post_processor = NULL, file_scope = NULL, on_exit = NULL )
output_format_dependency( name, pandoc = list(), pre_processor = NULL, post_processor = NULL, file_scope = NULL, on_exit = NULL )
name |
A dependency name. If some dependencies share the same name, then only the first one will be merged to the output format. |
pandoc |
Pandoc options for an output format (see
|
pre_processor |
An optional pre-processor function that receives the
|
post_processor |
An optional post-processor function that receives the
|
file_scope |
A function that will split markdown input to pandoc into
multiple named files. This is useful when the caller has concatenated a set
of Rmd files together (as bookdown does), and those files may need to
processed by pandoc using the |
on_exit |
A function to call when |
An list of arguments with the "rmd_dependency" class.
# Implicitly add lua filters from within a chunk # This relies on (implicit) printing of the dependency in a chunk via # knitr::knit_print()` output_format_dependency( "lua_filter1", pandoc = list(lua_filters = "example1.lua") ) # Explicitly add lua filters from within a chunk knitr::knit_meta_add(list(output_format_dependency( "lua_filter2", pandoc = list(lua_filters = "example2.lua") ))) # List the available dependencies # Note that the list may include dependencies with duplicated names. In that # case, the first one is merged to the output format and the others are # discarded. str(knitr::knit_meta("output_format_dependency", clean = FALSE))
# Implicitly add lua filters from within a chunk # This relies on (implicit) printing of the dependency in a chunk via # knitr::knit_print()` output_format_dependency( "lua_filter1", pandoc = list(lua_filters = "example1.lua") ) # Explicitly add lua filters from within a chunk knitr::knit_meta_add(list(output_format_dependency( "lua_filter2", pandoc = list(lua_filters = "example2.lua") ))) # List the available dependencies # Note that the list may include dependencies with duplicated names. In that # case, the first one is merged to the output format and the others are # discarded. str(knitr::knit_meta("output_format_dependency", clean = FALSE))
This object provides a mechanism for users to attach metadata as an attribute
(named rmd_output_metadata
) of the returned value of
render()
. The initial value of the metadata comes from in the
rmd_output_metadata
field of the YAML frontmatter of an R Markdown
document. The metadata can be queried via the
output_metadata$get()
method, and modified via the
output_metadata$set()
method.
Create a table in HTML with support for paging rows and columns
paged_table(x, options = NULL)
paged_table(x, options = NULL)
x |
a data frame to be rendered as a paged table. |
options |
options for printing the paged table. See details for specifics. |
Below are the recognized table pagination options.
Option | Description | Default |
max.print |
The number of rows to print. | 1000 |
sql.max.print |
The number of rows to print from a SQL data table. | 1000 |
rows.print |
The number of rows to display. | 10 |
cols.print |
The number of columns to display. | 10 |
cols.min.print |
The minimum number of columns to display. | - |
pages.print |
The number of pages to display under page navigation. | - |
paged.print |
When set to FALSE turns off paged tables. | TRUE |
rownames.print |
When set to FALSE turns off row names. | TRUE |
Note: There is a hard cap of 10,000 rows to ensure that pandoc will not fail when rendering the document.
Functions that assist in creating various types of pandoc command line arguments (e.g. for templates, table of contents, highlighting, and content includes).
pandoc_variable_arg(name, value) pandoc_metadata_arg(name, value) pandoc_metadata_file_arg(file) pandoc_include_args(in_header = NULL, before_body = NULL, after_body = NULL) pandoc_highlight_args(highlight, default = "tango") pandoc_latex_engine_args(latex_engine) pandoc_toc_args(toc, toc_depth = 3) pandoc_citeproc_args() pandoc_lua_filter_args(lua_files)
pandoc_variable_arg(name, value) pandoc_metadata_arg(name, value) pandoc_metadata_file_arg(file) pandoc_include_args(in_header = NULL, before_body = NULL, after_body = NULL) pandoc_highlight_args(highlight, default = "tango") pandoc_latex_engine_args(latex_engine) pandoc_toc_args(toc, toc_depth = 3) pandoc_citeproc_args() pandoc_lua_filter_args(lua_files)
name |
Name of template variable to set. |
value |
Value of template variable (defaults to |
file |
string. Path to a file |
in_header |
One or more files with content to be included in the header of the document. |
before_body |
One or more files with content to be included before the document body. |
after_body |
One or more files with content to be included after the document body. |
highlight |
The name of a pandoc syntax highlighting theme. |
default |
The highlighting theme to use if "default" is specified. |
latex_engine |
LaTeX engine for producing PDF output. Options are "pdflatex", "lualatex", "xelatex", and "tectonic". |
toc |
|
toc_depth |
Depth of headers to include in table of contents. |
lua_files |
Character vector of file paths to Lua filter files. Paths
will be transformed by |
Non-absolute paths for resources referenced from the
in_header
, before_body
, and after_body
parameters are resolved relative to the directory of the input document.
A character vector with pandoc command line arguments.
For Pandoc version before 2.11, a pandoc filter ‘pandoc-citeproc’ is used. Since Pandoc 2.11, the feature is built-in and activated using ‘--citeproc’ flag. ‘pandoc_citeproc_arg’ will return the correct switches depending on the Pandoc version in use.
## Not run: library(rmarkdown) pandoc_include_args(before_body = "header.htm") pandoc_include_args(before_body = "header.tex") pandoc_highlight_args("kate") pandoc_latex_engine_args("pdflatex") pandoc_toc_args(toc = TRUE, toc_depth = 2) ## End(Not run)
## Not run: library(rmarkdown) pandoc_include_args(before_body = "header.htm") pandoc_include_args(before_body = "header.tex") pandoc_highlight_args("kate") pandoc_latex_engine_args("pdflatex") pandoc_toc_args(toc = TRUE, toc_depth = 2) ## End(Not run)
Determine whether pandoc is currently available on the system (optionally checking for a specific version or greater). Determine the specific version of pandoc available.
pandoc_available(version = NULL, error = FALSE) pandoc_version()
pandoc_available(version = NULL, error = FALSE) pandoc_version()
version |
Required version of pandoc |
error |
Whether to signal an error if pandoc with the required version is not found |
The system environment variable ‘PATH’ as well as the version of pandoc shipped with RStudio (its location is set via the environment variable ‘RSTUDIO_PANDOC’ by RStudio products like the RStudio IDE, RStudio Server, Shiny Server, and RStudio Connect, etc) are scanned for pandoc and the highest version available is used. Please do not modify the environment variable ‘RSTUDIO_PANDOC’ unless you know what it means.
pandoc_available
returns a logical indicating whether the
required version of pandoc is available. pandoc_version
returns a
numeric_version
with the version of pandoc found.
## Not run: library(rmarkdown) if (pandoc_available()) cat("pandoc", as.character(pandoc_version()), "is available!\n") if (pandoc_available("1.12.3")) cat("required version of pandoc is available!\n") ## End(Not run)
## Not run: library(rmarkdown) if (pandoc_available()) cat("pandoc", as.character(pandoc_version()), "is available!\n") if (pandoc_available("1.12.3")) cat("required version of pandoc is available!\n") ## End(Not run)
Convert a bibliography file (e.g. a BibTeX file) to an R list, JSON text, or YAML text
pandoc_citeproc_convert(file, type = c("list", "json", "yaml"))
pandoc_citeproc_convert(file, type = c("list", "json", "yaml"))
file |
Bibliography file |
type |
Conversion type |
For 'type = "list"', and R list. For 'type = "json"' or 'type = "yaml"', a character vector with the specified format.
Convert documents to and from various formats using the pandoc utility.
pandoc_convert( input, to = NULL, from = NULL, output = NULL, citeproc = FALSE, options = NULL, verbose = FALSE, wd = NULL )
pandoc_convert( input, to = NULL, from = NULL, output = NULL, citeproc = FALSE, options = NULL, verbose = FALSE, wd = NULL )
input |
Character vector containing paths to input files (files must be UTF-8 encoded) |
to |
Format to convert to (if not specified, you must specify
|
from |
Format to convert from (if not specified then the format is
determined based on the file extension of |
output |
Output file (if not specified then determined based on format being converted to). |
citeproc |
|
options |
Character vector of command line options to pass to pandoc. |
verbose |
|
wd |
Working directory in which code will be executed. If not
supplied, defaults to the common base directory of |
Supported input and output formats are described in the pandoc user guide.
The system path as well as the version of pandoc shipped with RStudio (if running under RStudio) are scanned for pandoc and the highest version available is used.
## Not run: library(rmarkdown) # convert markdown to various formats pandoc_convert("input.md", to = "html") pandoc_convert("input.md", to = "latex") # process citations pandoc_convert("input.md", to = "html", citeproc = TRUE) # add some pandoc options pandoc_convert("input.md", to = "latex", options = c("--listings")) ## End(Not run)
## Not run: library(rmarkdown) # convert markdown to various formats pandoc_convert("input.md", to = "html") pandoc_convert("input.md", to = "latex") # process citations pandoc_convert("input.md", to = "html", citeproc = TRUE) # add some pandoc options pandoc_convert("input.md", to = "latex", options = c("--listings")) ## End(Not run)
Returns the path of the pandoc executable used by functions in the the rmarkdown package. This is the most recent version of pandoc found in either the system path or shipped with RStudio.
pandoc_exec()
pandoc_exec()
See the pandoc manual for pandoc commands.
Define the pandoc options for an R Markdown output format.
pandoc_options( to, from = rmarkdown_format(), args = NULL, keep_tex = FALSE, latex_engine = c("pdflatex", "lualatex", "xelatex", "tectonic"), ext = NULL, lua_filters = NULL, convert_fun = NULL )
pandoc_options( to, from = rmarkdown_format(), args = NULL, keep_tex = FALSE, latex_engine = c("pdflatex", "lualatex", "xelatex", "tectonic"), ext = NULL, lua_filters = NULL, convert_fun = NULL )
to |
Pandoc format to convert to |
from |
Pandoc format to convert from |
args |
Character vector of command line arguments to pass to pandoc |
keep_tex |
Keep the intermediate tex file used in the conversion to PDF (applies only to 'latex' and 'beamer' target formats) |
latex_engine |
LaTeX engine to producing PDF output (applies only to 'latex' and 'beamer' target formats) |
ext |
File extension (e.g. ".tex") for output file (if |
lua_filters |
Character vector of file paths to Lua filters to use with
this format. They will be added to pandoc command line call using
|
convert_fun |
A function to convert the input file to the desired output
format in |
The from
argument should be used very cautiously as it's important for
users to be able to rely on a stable definition of supported markdown
extensions.
An list that can be passed as the pandoc
argument of the
output_format
function.
output_format, rmarkdown_format
Transform a path for passing to pandoc on the command line. Calls
path.expand
on all platforms. On Windows,
transform it to a short path name if it contains spaces, and then convert
forward slashes to back slashes (as required by pandoc for some path
references).
pandoc_path_arg(path, backslash = TRUE)
pandoc_path_arg(path, backslash = TRUE)
path |
Path to transform |
backslash |
Whether to replace forward slashes in |
Transformed path that can be passed to pandoc on the command line.
Create a self-contained HTML document by base64 encoding images, scripts, and stylesheets referred by the input document.
pandoc_self_contained_html(input, output)
pandoc_self_contained_html(input, output)
input |
Input html file to create self-contained version of. |
output |
Path to save output. |
(Invisibly) The path of the generated file.
Use the pandoc templating engine to render a text file. Substitutions are
done using the metadata
list passed to the function.
pandoc_template(metadata, template, output, verbose = FALSE)
pandoc_template(metadata, template, output, verbose = FALSE)
metadata |
A named list containing metadata to pass to template. |
template |
Path to a pandoc template. |
output |
Path to save output. |
verbose |
|
(Invisibly) The path of the generated file.
Parse an HTML notebook, retrieving annotation information related to generated outputs in the document, as well as the original R Markdown source document.
parse_html_notebook(path)
parse_html_notebook(path)
path |
The path to an R Notebook file (with extension |
See the online
documentation for additional details on using the html_notebook
format.
Formats for converting from R Markdown to a PDF or LaTeX document.
pdf_document( toc = FALSE, toc_depth = 2, number_sections = FALSE, fig_width = 6.5, fig_height = 4.5, fig_crop = "auto", fig_caption = TRUE, dev = "pdf", df_print = "default", highlight = "default", template = "default", keep_tex = FALSE, keep_md = FALSE, latex_engine = "pdflatex", citation_package = c("default", "natbib", "biblatex"), includes = NULL, md_extensions = NULL, output_extensions = NULL, pandoc_args = NULL, extra_dependencies = NULL ) latex_document(...) latex_fragment(...)
pdf_document( toc = FALSE, toc_depth = 2, number_sections = FALSE, fig_width = 6.5, fig_height = 4.5, fig_crop = "auto", fig_caption = TRUE, dev = "pdf", df_print = "default", highlight = "default", template = "default", keep_tex = FALSE, keep_md = FALSE, latex_engine = "pdflatex", citation_package = c("default", "natbib", "biblatex"), includes = NULL, md_extensions = NULL, output_extensions = NULL, pandoc_args = NULL, extra_dependencies = NULL ) latex_document(...) latex_fragment(...)
toc |
|
toc_depth |
Depth of headers to include in table of contents |
number_sections |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_crop |
Whether to crop PDF figures with the command
|
fig_caption |
|
dev |
Graphics device to use for figure output (defaults to pdf) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
highlight |
Syntax highlighting style passed to Pandoc. Supported built-in styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock", and "breezedark". Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a path to a ‘.theme’ file to use a custom Pandoc style. Note that custom theme requires Pandoc 2.0+. Pass |
template |
Pandoc template to use for rendering. Pass "default" to use
the rmarkdown package default template; pass |
keep_tex |
Keep the intermediate tex file used in the conversion to PDF.
Note that this argument does not control whether to keep the auxiliary
files (e.g., ‘.aux’) generated by LaTeX when compiling ‘.tex’ to
‘.pdf’. To keep these files, you may set |
keep_md |
Keep the markdown file generated by knitting. |
latex_engine |
LaTeX engine for producing PDF output. Options are "pdflatex", "lualatex", "xelatex" and "tectonic". |
citation_package |
The LaTeX package to process citations, |
includes |
Named list of additional content to include within the
document (typically created using the |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
output_extensions |
Pandoc extensions to be added or removed from the
output format, e.g., |
pandoc_args |
Additional command line options to pass to pandoc |
extra_dependencies |
A LaTeX dependency |
... |
Arguments passed to |
See the online
documentation for additional details on using the pdf_document
format.
Creating PDF output from R Markdown requires that LaTeX be installed.
R Markdown documents can have optional metadata that is used to generate a document header that includes the title, author, and date. For more details see the documentation on R Markdown metadata.
R Markdown documents also support citations. You can find more information on the markdown syntax for citations in the Bibliographies and Citations article in the online documentation.
Many aspects of the LaTeX template used to create PDF documents can be customized using metadata. For example:
--- |
title: "Crop Analysis Q3 2013" |
fontsize: 11pt |
geometry: margin=1in |
---
|
Available metadata variables include:
lang
Document language code (e.g. "es", "fr", "pt-BR")
fontsize
Font size (e.g. 10pt, 11pt, 12pt)
documentclass
LaTeX document class (e.g. article)
classoption
Option for documentclass
(e.g. oneside); may be repeated
geometry
Options for geometry class (e.g. margin=1in); may be repeated
mainfont, sansfont, monofont, mathfont
Document fonts (works only with xelatex and lualatex, see the latex_engine
option)
linkcolor, urlcolor, citecolor
Color for internal, external, and citation links (red, green, magenta, cyan, blue, black)
linestretch
Options for line spacing (e.g. 1, 1.5, 3)
R Markdown output format to pass to render
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", pdf_document()) # specify an option for latex engine render("input.Rmd", pdf_document(latex_engine = "lualatex")) # add a table of contents and pass an option to pandoc render("input.Rmd", pdf_document(toc = TRUE, "--listings")) ## End(Not run)
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", pdf_document()) # specify an option for latex engine render("input.Rmd", pdf_document(latex_engine = "lualatex")) # add a table of contents and pass an option to pandoc render("input.Rmd", pdf_document(toc = TRUE, "--listings")) ## End(Not run)
Lua filters stored in a source package in the ‘inst/rmarkdown/lua’ directory will be installed to the ‘rmarkdown/lua’ directory in the package path. This function finds the full paths of the Lua filters in the installed packages.
pkg_file_lua(filters = NULL, package = "rmarkdown")
pkg_file_lua(filters = NULL, package = "rmarkdown")
filters |
A character vector of filenames for Lua filters to be
retrieved in ‘rmarkdown/lua’ folder of the package. By default
( |
package |
The name of the package in which to look for the filters. |
A character vector of absolute file paths for the Lua filter from the
package. The returned paths have been processed by
pandoc_path_arg()
, so they are ready to be used by Pandoc.
# list all Lua filters stored in the rmarkdown package pkg_file_lua() # get a specific filter pkg_file_lua(c("pagebreak.lua", "latex_div.lua"))
# list all Lua filters stored in the rmarkdown package pkg_file_lua() # get a specific filter pkg_file_lua(c("pagebreak.lua", "latex_div.lua"))
Format for converting from R Markdown to a PowerPoint presentation. Pandoc v2.0.5 or above is required.
powerpoint_presentation( toc = FALSE, toc_depth = 2, number_sections = FALSE, incremental = FALSE, fig_width = 5, fig_height = 4, fig_caption = TRUE, df_print = "default", keep_md = FALSE, md_extensions = NULL, slide_level = NULL, reference_doc = "default", pandoc_args = NULL )
powerpoint_presentation( toc = FALSE, toc_depth = 2, number_sections = FALSE, incremental = FALSE, fig_width = 5, fig_height = 4, fig_caption = TRUE, df_print = "default", keep_md = FALSE, md_extensions = NULL, slide_level = NULL, reference_doc = "default", pandoc_args = NULL )
toc |
|
toc_depth |
Depth of headers to include in table of contents |
number_sections |
|
incremental |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_caption |
|
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
keep_md |
Keep the markdown file generated by knitting. |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
slide_level |
The heading level which defines individual slides. By
default this is the highest header level in the hierarchy that is followed
immediately by content, and not another header, somewhere in the document.
This default can be overridden by specifying an explicit
|
reference_doc |
Path to a PowerPoint template. |
pandoc_args |
Additional command line options to pass to pandoc |
R Markdown output format to pass to render()
Publish a website to RStudio Connect
publish_site( site_dir = ".", site_name = NULL, method = c("rsconnect"), server = NULL, account = NULL, render = TRUE, launch_browser = interactive() )
publish_site( site_dir = ".", site_name = NULL, method = c("rsconnect"), server = NULL, account = NULL, render = TRUE, launch_browser = interactive() )
site_dir |
Directory containing website. Defaults to current working directory. |
site_name |
Name for the site (names must be unique within an account). Defaults to the 'name' provided by the site generator (or to the name of the site_dir if there is no 'name' specified). |
method |
Publishing method (currently only "rsconnect" is available) |
account , server
|
Uniquely identify a remote server with either your
user Use |
render |
'TRUE' to render the site locally before publishing. |
launch_browser |
If ‘TRUE', the system’s default web browser will be launched automatically after the site is deployed. Defaults to 'TRUE' in interactive sessions only. |
## Not run: library(rmarkdown) publish_site() ## End(Not run)
## Not run: library(rmarkdown) publish_site() ## End(Not run)
Given a directory and a file, return a relative path from the directory to the file, or the unmodified file path if the file does not appear to be in the directory.
relative_to(dir, file)
relative_to(dir, file)
dir |
Directory |
file |
File |
Relative path from the directory to the file (or the unmodified file path if the file does not appear to be in the directory).
Render the input file to the specified output format using pandoc. If the
input requires knitting then knit
is called prior
to pandoc.
render( input, output_format = NULL, output_file = NULL, output_dir = NULL, output_options = NULL, output_yaml = NULL, intermediates_dir = NULL, knit_root_dir = NULL, runtime = c("auto", "static", "shiny", "shinyrmd", "shiny_prerendered"), clean = TRUE, params = NULL, knit_meta = NULL, envir = parent.frame(), run_pandoc = TRUE, quiet = FALSE, encoding = "UTF-8" )
render( input, output_format = NULL, output_file = NULL, output_dir = NULL, output_options = NULL, output_yaml = NULL, intermediates_dir = NULL, knit_root_dir = NULL, runtime = c("auto", "static", "shiny", "shinyrmd", "shiny_prerendered"), clean = TRUE, params = NULL, knit_meta = NULL, envir = parent.frame(), run_pandoc = TRUE, quiet = FALSE, encoding = "UTF-8" )
input |
The input file to be rendered. This can be an R script (.R), an R Markdown document (.Rmd), or a plain markdown document. |
output_format |
The R Markdown output format to convert to. The option
|
output_file |
The name of the output file. If using |
output_dir |
The output directory for the rendered |
output_options |
List of output options that can override the options
specified in metadata (e.g. could be used to force |
output_yaml |
Paths to YAML files specifying output formats and their
configurations. The first existing one is used. If none are found, then
the function searches YAML files specified to the |
intermediates_dir |
Intermediate files directory. If a path is specified
then intermediate files will be written to that path. If |
knit_root_dir |
The working directory in which to knit the document;
uses knitr's |
runtime |
The runtime target for rendering. The |
clean |
Using |
params |
A list of named parameters that override custom params
specified within the YAML front-matter (e.g. specifying a dataset to read or
a date range to confine output to). Pass |
knit_meta |
(This option is reserved for expert use.) Metadata generated by knitr. |
envir |
The environment in which the code chunks are to be evaluated
during knitting (can use |
run_pandoc |
An option for whether to run pandoc to convert Markdown output. |
quiet |
An option to suppress printing during rendering from knitr,
pandoc command line and others. To only suppress printing of the last
"Output created: " message, you can set |
encoding |
Ignored. The encoding is always assumed to be UTF-8. |
Note that the knitr error
option is set to FALSE
during
rendering (which is different from the knitr default value of
TRUE
).
For additional details on rendering R scripts see Compiling R scripts to a notebook.
If no output_format
parameter is specified then the output format is
read from the YAML front-matter of the input file. For example, the
following YAML would yield a PDF document:
output: pdf_document
Additional format options can also be specified in metadata. For example:
output: pdf_document: toc: true highlight: zenburn
Multiple formats can be specified in metadata. If no output_format
is passed to render
then the first one defined will be used:
output: pdf_document: toc: true highlight: zenburn html_document: toc: true theme: united
Formats specified in metadata can be any one of the built in formats (e.g.
html_document
, pdf_document
) or a format defined
in another package (e.g. pkg::custom_format
).
If there is no format defined in the YAML then
html_document
will be used.
When run_pandoc = TRUE
, the compiled document is written into
the output file, and the path of the output file is returned. When
run_pandoc = FALSE
, the path of the Markdown output file, with
attributes knit_meta
(the knitr meta data collected from code
chunks) and intermediates
(the intermediate files/directories
generated by render()
).
R Markdown supports all of the base pandoc markdown features as well as some
optional features for compatibility with GitHub Flavored Markdown (which
previous versions of R Markdown were based on). See
rmarkdown_format
for details.
knit, output_format, https://pandoc.org
## Not run: library(rmarkdown) # Render the default (first) format defined in the file render("input.Rmd") # Render all formats defined in the file render("input.Rmd", "all") # Render a single format, using parameters for \code{html_document} from # the YAML header parameters. render("input.Rmd", "html_document") # Render a single format, ignoring parameters for \code{html_document} in # the YAML header. Any parameters not passed as arguments to # \code{html_document()} will be assigned to their default values, regardless # of anything in the YAML header render("input.Rmd", html_document(toc = TRUE, toc_depth = 2)) # Render multiple formats render("input.Rmd", c("html_document", "pdf_document")) ## End(Not run)
## Not run: library(rmarkdown) # Render the default (first) format defined in the file render("input.Rmd") # Render all formats defined in the file render("input.Rmd", "all") # Render a single format, using parameters for \code{html_document} from # the YAML header parameters. render("input.Rmd", "html_document") # Render a single format, ignoring parameters for \code{html_document} in # the YAML header. Any parameters not passed as arguments to # \code{html_document()} will be assigned to their default values, regardless # of anything in the YAML header render("input.Rmd", html_document(toc = TRUE, toc_depth = 2)) # Render multiple formats render("input.Rmd", c("html_document", "pdf_document")) ## End(Not run)
In a Shiny document, evaluate the given expression after the document has finished rendering, instead of during render.
render_delayed(expr)
render_delayed(expr)
expr |
The expression to evaluate. |
This function is useful inside Shiny documents. It delays the evaluation of its argument until the document has finished its initial render, so that the document can be viewed before the calculation is finished.
Any expression that returns HTML can be wrapped in render_delayed
.
An object representing the expression.
expr
is evaluated in a copy of the environment in which
the render_delayed
call appears. Consequently, no side effects
created by expr
are visible in succeeding expressions, nor are
changes to the environment after the call to render_delayed
visible
to expr
.
expr
must be an expression that produces HTML.
## Not run: # Add the following code to an R Markdown document div(Sys.time()) render_delayed({ Sys.sleep(3) # simulate an expensive computation div(Sys.time()) }) div(Sys.time()) ## End(Not run)
## Not run: # Add the following code to an R Markdown document div(Sys.time()) render_delayed({ Sys.sleep(3) # simulate an expensive computation div(Sys.time()) }) div(Sys.time()) ## End(Not run)
Render all of the R Markdown documents within a directory as a website.
render_site( input = ".", output_format = "all", envir = parent.frame(), quiet = FALSE, encoding = "UTF-8" ) clean_site(input = ".", preview = TRUE, quiet = FALSE, encoding = "UTF-8") site_generator(input = ".", output_format = NULL) site_config(input = ".", encoding = "UTF-8") default_site_generator(input, output_format_filter = NULL, ...)
render_site( input = ".", output_format = "all", envir = parent.frame(), quiet = FALSE, encoding = "UTF-8" ) clean_site(input = ".", preview = TRUE, quiet = FALSE, encoding = "UTF-8") site_generator(input = ".", output_format = NULL) site_config(input = ".", encoding = "UTF-8") default_site_generator(input, output_format_filter = NULL, ...)
input |
Website directory (or the name of a file within the directory). |
output_format |
R Markdown format to convert to (defaults to "all"). |
envir |
The environment in which the code chunks are to be evaluated
during knitting (can use |
quiet |
|
encoding |
Ignored. The encoding is always assumed to be UTF-8. |
preview |
Whether to list the files to be removed rather than actually removing them. Defaulting to TRUE to prevent removing without notice. |
output_format_filter |
An optional function which is passed the input file and the output format, and which returns a (potentially modified) output format. |
... |
Currently unused. |
The render_site
function enables you to render a collection of
markdown documents within a directory as a website. There are two
requirements for a directory to be rendered as a website:
It must contain either an "index.Rmd" or "index.md" file.
It must contain a site configuration file ("_site.yml").
The most minimal valid website is an empty "index.Rmd" and an empty
"_site.yml". With this configuration a single empty webpage would be
generated via a call to render_site
. If you add additional markdown
documents to the directory they will also be rendered. By default a site is
rendered in the following fashion:
R Markdown (.Rmd) and plain markdown (.md) files in the root directory are rendered. Note however that markdown files beginning with "_" are not rendered (this is a convention to designate files that are included by top level documents).
All output and supporting files are copied to a "_site" subdirectory of the website directory (this is configurable, see discussion below).
The following files are not copied to the "_site" sub-directory:
Files beginning with "." (hidden files).
Files beginning with "_"
Files known to contain R source code (e.g. ".R", ".s", ".Rmd"), R data (e.g. ".RData", ".rds"), configuration data (e.g. ".Rproj", "rsconnect") or package project management data (e.g. "packrat", "renv").
Note that you can override which files are included or excluded via settings in "_site.yml" (described below).
Normally R Markdown renders documents as self-contained HTML.
However, render_site
ensures that dependencies (e.g. CSS,
JavaScript, images, etc.) remain in external files. CSS/JavaScript
libraries are copied to a "site_libs" sub-directory and plots/images are
copied to "_files" sub-directories.
You can remove the files generated by render_site
using the
clean_site
function.
render_site
returns the name of the site output file (relative
to the input directory). clean_site
returns the names of the
generated files removed during cleaning. site_config
returns the
contents of _site.yml as an R list. default_site_generator
returns
the default site generator for R Markdown websites.
A "_site.yml" file can be used to configure the behavior of site generation. Here is an example configuration file:
name: my-website output_dir: _site include: ["demo.R"] exclude: ["docs.txt", "*.csv"] navbar: title: "My Website" left: - text: "Home" href: index.html - text: "About" href: about.html output: html_document: toc: true highlight: textmate
The name
field provides a suggested URL path for your website when it
is published (by default this is just the name of the directory containing
the site). The output_dir
indicates which directory to copy site
content into ("_site" is the default if none is specified). Note that this
can be "." to keep all content within the root website directory alongside
the source code.
The include
and exclude
fields enable you to override the
default behavior vis-a-vis what files are copied into the "_site" directory
(wildcards can be used as in the above example).
The navbar
field can be used to define a navigation bar for websites
based on the html_document
format.
Finally, the output
field enables you to specify output options that
are common to all documents within the website (you can also still provide
local options within each document that override any common options).
new_session: true
causes each file to be rendered in a new R session.
This prevents the masking problem that arises when different files use
functions from different packages (namespaces) that share a common name, such
as here::here
and lubridate::here
or dplyr::filter
and
MASS::filter
. The default behaviour of render_site
is to use a
common R session.
autospin: true
causes .R
files to be spinned and rendered
(as well as .Rmd
files). If autospin
is set to false (the default),
.R
files will not be spinned nor rendered. autospin
can also
enumerate a list of .R files to be spinned and rendered.
The behavior of the default site generation function
(rmarkdown::default_site
) is described above. It is also possible to
define a custom site generator that has alternate behavior. A site generator
is an R function that is bound to by including it in the "site:" field of the
"index.Rmd" or "index.md" file. For example:
title: "My Book" output: bookdown::gitbook site: bookdown::bookdown_site
A site generation function should return a list with the following elements:
name
:The name for the website (e.g. the parent directory name).
output_dir
:The directory where the website output is written to. This path should be relative to the site directory (e.g. "." or "_site")
render
:An R function that can be called to generate the
site. The function should accept the input_file
,
output_format
, envir
, and quiet
arguments.
clean
:An R function that returns relative paths to the files
generated by render_site
(these files are the ones which will be
removed by the clean_site
function.
subdirs
(optional):A logical flag that indicates if
the generator supports nested source files in subdirectories of the project
(TRUE
) or only at the project root (FALSE
). (e.g.
blogdown:::blogdown_site()
)
Note that the input_file
argument will be NULL
when the entire
site is being generated. It will be set to a specific file name if a
front-end tool is attempting to preview it (e.g. RStudio IDE via the Knit
button).
When quiet = FALSE
the render
function should also print a line
of output using the message
function indicating which output
file should be previewed, for example:
if (!quiet) message("\nOutput created: ", output)
Emitting this line enables front-ends like RStudio to determine which file they should open to preview the website.
See the source code of the rmarkdown::default_site
function for a
example of a site generation function.
Render (copy) required supporting files for an input document to the
_files
directory that is associated with the document.
render_supporting_files(from, files_dir, rename_to = NULL)
render_supporting_files(from, files_dir, rename_to = NULL)
from |
The directory from which the files should be copied. |
files_dir |
The directory that will receive the copied files. |
rename_to |
An option to rename the source directory after the copy operation is complete. |
The relative path to the supporting files. This path is suitable
for inclusion in HTMLhref
and src
attributes.
Read the YAML metadata (and any common output YAML file) for the
document and return an output format object that can be
passed to the render
function.
resolve_output_format( input, output_format = NULL, output_options = NULL, output_yaml = NULL )
resolve_output_format( input, output_format = NULL, output_options = NULL, output_yaml = NULL )
input |
Input file (Rmd or plain markdown) |
output_format |
Name of output format (or |
output_options |
List of output options that should override the options specified in metadata. |
output_yaml |
Paths to YAML files specifying output formats and their
configurations. The first existing one is used. If none are found, then
the function searches YAML files specified to the |
This function is useful for front-end tools that need to modify the default behavior of an output format.
An R Markdown output format definition that can be passed to
render
.
Compose a pandoc markdown input definition for R Markdown
that can be passed as the from
argument of pandoc_options.
rmarkdown_format(extensions = NULL) from_rmarkdown(implicit_figures = TRUE, extensions = NULL)
rmarkdown_format(extensions = NULL) from_rmarkdown(implicit_figures = TRUE, extensions = NULL)
extensions |
Markdown extensions to be added or removed from the default definition of R Markdown. |
implicit_figures |
Automatically make figures from images (defaults to |
By default R Markdown is defined as all pandoc markdown extensions with the following tweaks for backward compatibility with the markdown package (+ features are added, - features are removed):
+autolink_bare_uris |
+tex_math_single_backslash |
For more on pandoc markdown see the pandoc online documentation.
Pandoc markdown format specification
## Not run: rmarkdown_format("-implicit_figures") ## End(Not run)
## Not run: rmarkdown_format("-implicit_figures") ## End(Not run)
Rmd files include a metadata section (typically located at the top of the
file) that can specify (among other things) the title, author, and date of
the document. Metadata adheres to the YAML format
and is delimited by lines containing three dashes (---
). Here is an
example metadata section:
--- title: "Crop Analysis Q3 2013" author: Martha Smith date: October 23rd, 2013 ---
Note that the title
field is quoted. This is because titles often
contained embedded colons (:
) and colons followed by a space need to
be quoted in YAML.
When title, author, and date metadata is provided it's used to automatically create a title section within output documents. If you don't want this section included in your document then you should remove the corresponding metadata fields.
When generating PDF and Beamer output there are also a number of other
metadata fields that can be included to customize the appearance and theme
of PDF output. For more details see the documentation for
pdf_document
and beamer_presentation
.
Format for converting from R Markdown to an RTF document.
rtf_document( toc = FALSE, toc_depth = 3, number_sections = FALSE, fig_width = 5, fig_height = 4, keep_md = FALSE, md_extensions = NULL, pandoc_args = NULL )
rtf_document( toc = FALSE, toc_depth = 3, number_sections = FALSE, fig_width = 5, fig_height = 4, keep_md = FALSE, md_extensions = NULL, pandoc_args = NULL )
toc |
|
toc_depth |
Depth of headers to include in table of contents |
number_sections |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
keep_md |
Keep the markdown file generated by knitting. |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
See the online
documentation for additional details on using the rtf_document
format.
R Markdown documents can have optional metadata that is used to generate a document header that includes the title, author, and date. For more details see the documentation on R Markdown metadata.
R Markdown documents also support citations. You can find more information on the markdown syntax for citations in the Bibliographies and Citations article in the online documentation.
R Markdown output format to pass to render
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", rtf_document()) # specify table of contents option render("input.Rmd", rtf_document(toc = TRUE)) ## End(Not run)
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", rtf_document()) # specify table of contents option render("input.Rmd", rtf_document(toc = TRUE)) ## End(Not run)
Start a Shiny server for the given document, and render it for display.
run( file = "index.Rmd", dir = dirname(file), default_file = NULL, auto_reload = TRUE, shiny_args = NULL, render_args = NULL )
run( file = "index.Rmd", dir = dirname(file), default_file = NULL, auto_reload = TRUE, shiny_args = NULL, render_args = NULL )
file |
Path to the R Markdown document to launch in a web browser.
Defaults to |
dir |
The directory from which to to read input documents. Defaults to
the parent directory of |
default_file |
The file to serve at the Shiny server's root URL. If
|
auto_reload |
If |
shiny_args |
Additional arguments to |
render_args |
Additional arguments to |
The run
function runs a Shiny document by starting a Shiny
server associated with the document. The shiny_args
parameter can be
used to configure the server; see the runApp
documentation for details.
Once the server is started, the document will be rendered using
render
. The server will initiate a render of the document
whenever necessary, so it is not necessary to call run
every time
the document changes: if auto_reload
is TRUE
, saving the
document will trigger a render. You can also manually trigger a render by
reloading the document in a Web browser.
The server will render any R Markdown (.Rmd
) document in dir
;
the file
argument specifies only the initial document to be
rendered and viewed. You can therefore link to other documents in the
directory using standard Markdown syntax, e.g.
[Analysis Page 2](page2.Rmd)
.
If default_file
is not specified, nor is a file specified on the
URL, then the default document to serve at /
is chosen from (in
order of preference):
If dir
contains only one Rmd
, that Rmd
.
The file ‘index.Rmd’, if it exists in dir
.
The first Rmd
that has runtime: shiny
in its YAML metadata.
The file ‘index.html’ (or ‘index.htm’), if it exists in dir
.
If you wish to share R code between your documents, place it in a file
named global.R
in dir
; it will be sourced into the global
environment.
Invisible NULL.
Unlike render
, run
does not render the document to
a file on disk. In most cases a Web browser will be started automatically
to view the document; see launch.browser
in the
runApp
documentation for details.
When using an external web browser with the server, specify the name of the
R Markdown file to view in the URL (e.g.
http://127.0.0.1:1234/foo.Rmd
). A URL without a filename will show
the default_file
as described above.
## Not run: # Run the Shiny document "index.Rmd" in the current directory rmarkdown::run() # Run the Shiny document "shiny_doc.Rmd" on port 8241 rmarkdown::run("shiny_doc.Rmd", shiny_args = list(port = 8241)) ## End(Not run)
## Not run: # Run the Shiny document "index.Rmd" in the current directory rmarkdown::run() # Run the Shiny document "shiny_doc.Rmd" on port 8241 rmarkdown::run("shiny_doc.Rmd", shiny_args = list(port = 8241)) ## End(Not run)
Programmatic equivalent to including a code chunk with a context in a runtime: shiny_prerendered document.
shiny_prerendered_chunk(context, code, singleton = FALSE)
shiny_prerendered_chunk(context, code, singleton = FALSE)
context |
Context name (e.g. "server", "server-start") |
code |
Character vector with code |
singleton |
Collapse multiple identical versions of this chunk into a single chunk. |
Remove the associated html file and supporting _files directory for a shiny_prerendered documet.
shiny_prerendered_clean(input)
shiny_prerendered_clean(input)
input |
Rmd input file to clean content for |
Determine which files within a given directory should be copied in order to serve a website from the directory. Attempts to automatically exclude source, data, hidden, and other files not required to serve website content.
site_resources(site_dir, include = NULL, exclude = NULL, recursive = FALSE)
site_resources(site_dir, include = NULL, exclude = NULL, recursive = FALSE)
site_dir |
Site directory to analyze |
include |
Additional files to include (glob wildcards supported) |
exclude |
Files to exclude (glob wildcards supported) |
recursive |
|
Character vector of files and directories to copy
Format for converting from R Markdown to a slidy presentation.
slidy_presentation( number_sections = FALSE, incremental = FALSE, slide_level = NULL, duration = NULL, footer = NULL, font_adjustment = 0, fig_width = 8, fig_height = 6, fig_retina = 2, fig_caption = TRUE, dev = "png", df_print = "default", self_contained = TRUE, highlight = "default", math_method = "default", mathjax = "default", template = "default", css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, md_extensions = NULL, pandoc_args = NULL, extra_dependencies = NULL, ... )
slidy_presentation( number_sections = FALSE, incremental = FALSE, slide_level = NULL, duration = NULL, footer = NULL, font_adjustment = 0, fig_width = 8, fig_height = 6, fig_retina = 2, fig_caption = TRUE, dev = "png", df_print = "default", self_contained = TRUE, highlight = "default", math_method = "default", mathjax = "default", template = "default", css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, md_extensions = NULL, pandoc_args = NULL, extra_dependencies = NULL, ... )
number_sections |
|
incremental |
|
slide_level |
The heading level which defines individual slides. By
default this is the highest header level in the hierarchy that is followed
immediately by content, and not another header, somewhere in the document.
This default can be overridden by specifying an explicit
|
duration |
Duration (in minutes) of the slide deck. This value is used to add a countdown timer to the slide footer. |
footer |
Footer text (e.g. organization name and/or copyright) |
font_adjustment |
Increase or decrease the default font size (e.g. -1 or +1). You can also manually adjust the font size during the presentation using the 'S' (smaller) and 'B' (bigger) keys. |
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays (defaults to 2, which
currently works for all widely used retina displays). Set to |
fig_caption |
|
dev |
Graphics device to use for figure output (defaults to pdf) |
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
self_contained |
Produce a standalone HTML file with no external dependencies, using data: URIs to incorporate the contents of linked scripts, stylesheets, images, and videos. Note that even for self contained documents MathJax is still loaded externally (this is necessary because of its size). |
highlight |
Syntax highlighting style passed to Pandoc. Supported built-in styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock", and "breezedark". Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a path to a ‘.theme’ file to use a custom Pandoc style. Note that custom theme requires Pandoc 2.0+. Pass |
math_method |
Math rendering engine to use. This will define the math method to use with Pandoc.
For example, output: html_document: math_method: engine: katex url: https://cdn.jsdelivr.net/npm/[email protected]/dist See Pandoc's Manual about Math in HTML for the details about Pandoc supported methods. Using |
mathjax |
Include mathjax. The "default" option uses an https URL from a
MathJax CDN. The "local" option uses a local version of MathJax (which is
copied into the output directory). You can pass an alternate URL or pass
|
template |
Pandoc template to use for rendering. Pass "default" to use
the rmarkdown package default template; pass |
css |
One or more css files to include. |
includes |
Named list of additional content to include within the
document (typically created using the |
keep_md |
Keep the markdown file generated by knitting. |
lib_dir |
Directory to copy dependent HTML libraries (e.g. jquery,
bootstrap, etc.) into. By default this will be the name of the document with
|
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
extra_dependencies |
A LaTeX dependency |
... |
Additional function arguments to pass to the base R Markdown HTML
output formatter |
See the online
documentation for additional details on using the slidy_presentation
format.
For more information on markdown syntax for presentations see the pandoc online documentation.
R Markdown output format to pass to render
## Not run: library(rmarkdown) # simple invocation render("pres.Rmd", slidy_presentation()) # specify an option for incremental rendering render("pres.Rmd", slidy_presentation(incremental = TRUE)) ## End(Not run)
## Not run: library(rmarkdown) # simple invocation render("pres.Rmd", slidy_presentation()) # specify an option for incremental rendering render("pres.Rmd", slidy_presentation(incremental = TRUE)) ## End(Not run)
Format for converting from R Markdown to an MS Word document.
word_document( toc = FALSE, toc_depth = 3, number_sections = FALSE, fig_width = 5, fig_height = 4, fig_caption = TRUE, df_print = "default", highlight = "default", reference_docx = "default", keep_md = FALSE, md_extensions = NULL, pandoc_args = NULL )
word_document( toc = FALSE, toc_depth = 3, number_sections = FALSE, fig_width = 5, fig_height = 4, fig_caption = TRUE, df_print = "default", highlight = "default", reference_docx = "default", keep_md = FALSE, md_extensions = NULL, pandoc_args = NULL )
toc |
|
toc_depth |
Depth of headers to include in table of contents |
number_sections |
|
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_caption |
|
df_print |
Method to be used for printing data frames. Valid values
include "default", "kable", "tibble", and "paged". The "default" method
uses a corresponding S3 method of |
highlight |
Syntax highlighting style passed to Pandoc. Supported built-in styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock", and "breezedark". Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a path to a ‘.theme’ file to use a custom Pandoc style. Note that custom theme requires Pandoc 2.0+. Pass |
reference_docx |
Use the specified file as a style reference in producing a docx file. For best results, the reference docx should be a modified version of a docx file produced using pandoc. Pass "default" to use the rmarkdown default styles. |
keep_md |
Keep the markdown file generated by knitting. |
md_extensions |
Markdown extensions to be added or removed from the
default definition of R Markdown. See the |
pandoc_args |
Additional command line options to pass to pandoc |
See the online
documentation for additional details on using the word_document
format.
R Markdown documents can have optional metadata that is used to generate a document header that includes the title, author, and date. For more details see the documentation on R Markdown metadata.
R Markdown documents also support citations. You can find more information on the markdown syntax for citations in the Bibliographies and Citations article in the online documentation.
R Markdown output format to pass to render
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", word_document()) # specify an option for syntax highlighting render("input.Rmd", word_document(highlight = "zenburn")) ## End(Not run)
## Not run: library(rmarkdown) # simple invocation render("input.Rmd", word_document()) # specify an option for syntax highlighting render("input.Rmd", word_document(highlight = "zenburn")) ## End(Not run)