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", "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 of the pandoc command line. |
encoding | Ignored. The encoding is always assumed to be UTF-8. |
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()
).
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.
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.
if (FALSE) { 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 render("input.Rmd", "html_document") # Render multiple formats render("input.Rmd", c("html_document", "pdf_document")) }