| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/render.R |
| 3 |
\name{render} |
| 4 |
\alias{render} |
| 5 |
\title{Render R Markdown} |
| 6 |
\usage{ |
| 7 |
render( |
| 8 |
input, |
| 9 |
output_format = NULL, |
| 10 |
output_file = NULL, |
| 11 |
output_dir = NULL, |
| 12 |
output_options = NULL, |
| 13 |
output_yaml = NULL, |
| 14 |
intermediates_dir = NULL, |
| 15 |
knit_root_dir = NULL, |
| 16 |
runtime = c("auto", "static", "shiny", "shinyrmd", "shiny_prerendered"), |
| 17 |
clean = TRUE, |
| 18 |
params = NULL, |
| 19 |
knit_meta = NULL, |
| 20 |
envir = parent.frame(), |
| 21 |
run_pandoc = TRUE, |
| 22 |
quiet = FALSE, |
| 23 |
encoding = "UTF-8" |
| 24 |
) |
| 25 |
} |
| 26 |
\arguments{ |
| 27 |
\item{input}{The input file to be rendered. This can be an R script (.R), |
| 28 |
an R Markdown document (.Rmd), or a plain markdown document.} |
| 29 |
|
| 30 |
\item{output_format}{The R Markdown output format to convert to. The option |
| 31 |
\code{"all"} will render all formats defined within the file. The option can |
| 32 |
be the name of a format (e.g. \code{"html_document"}) and that will render |
| 33 |
the document to that single format. One can also use a vector of format |
| 34 |
names to render to multiple formats. Alternatively, you can pass an output |
| 35 |
format object (e.g. \code{html_document()}). If using \code{NULL} then the |
| 36 |
output format is the first one defined in the YAML frontmatter in the input |
| 37 |
file (this defaults to HTML if no format is specified there). |
| 38 |
If you pass an output format object to \code{output_format}, the options |
| 39 |
specified in the YAML header or \code{_output.yml} will be ignored and you |
| 40 |
must explicitly set all the options you want when you construct the object. |
| 41 |
If you pass a string, the output format will use the output parameters in |
| 42 |
the YAML header or \code{_output.yml}.} |
| 43 |
|
| 44 |
\item{output_file}{The name of the output file. If using \code{NULL} then the |
| 45 |
output filename will be based on filename for the input file. If a filename |
| 46 |
is provided, a path to the output file can also be provided. Note that the |
| 47 |
\code{output_dir} option allows for specifying the output file path as well, |
| 48 |
however, if also specifying the path, the directory must exist. If |
| 49 |
\code{output_file} is specified but does not have a file extension, an |
| 50 |
extension will be automatically added according to the output format. To |
| 51 |
avoid the automatic file extension, put the \code{output_file} value in |
| 52 |
\code{\link{I}()}, e.g., \code{I('my-output')}.} |
| 53 |
|
| 54 |
\item{output_dir}{The output directory for the rendered \code{output_file}. |
| 55 |
This allows for a choice of an alternate directory to which the output file |
| 56 |
should be written (the default output directory of that of the input file). |
| 57 |
If a path is provided with a filename in \code{output_file} the directory |
| 58 |
specified here will take precedence. Please note that any directory path |
| 59 |
provided will create any necessary directories if they do not exist.} |
| 60 |
|
| 61 |
\item{output_options}{List of output options that can override the options |
| 62 |
specified in metadata (e.g. could be used to force \code{self_contained} or |
| 63 |
\code{mathjax = "local"}). Note that this is only valid when the output |
| 64 |
format is read from metadata (i.e. not a custom format object passed to |
| 65 |
\code{output_format}).} |
| 66 |
|
| 67 |
\item{output_yaml}{Paths to YAML files specifying output formats and their |
| 68 |
configurations. The first existing one is used. If none are found, then |
| 69 |
the function searches YAML files specified to the \code{output_yaml} top-level |
| 70 |
parameter in the YAML front matter, _output.yml or _output.yaml, and then uses |
| 71 |
the first existing one.} |
| 72 |
|
| 73 |
\item{intermediates_dir}{Intermediate files directory. If a path is specified |
| 74 |
then intermediate files will be written to that path. If \code{NULL}, |
| 75 |
intermediate files are written to the same directory as the input file.} |
| 76 |
|
| 77 |
\item{knit_root_dir}{The working directory in which to knit the document; |
| 78 |
uses knitr's \code{root.dir} knit option. If \code{NULL} then the behavior |
| 79 |
will follow the knitr default, which is to use the parent directory of the |
| 80 |
document.} |
| 81 |
|
| 82 |
\item{runtime}{The runtime target for rendering. The \code{static} option |
| 83 |
produces output intended for static files; \code{shiny} produces output |
| 84 |
suitable for use in a Shiny document (see \code{\link{run}}). The default, |
| 85 |
\code{auto}, allows the \code{runtime} target specified in the YAML metadata |
| 86 |
to take precedence, and renders for a \code{static} runtime target otherwise.} |
| 87 |
|
| 88 |
\item{clean}{Using \code{TRUE} will clean intermediate files that are created |
| 89 |
during rendering.} |
| 90 |
|
| 91 |
\item{params}{A list of named parameters that override custom params |
| 92 |
specified within the YAML front-matter (e.g. specifying a dataset to read or |
| 93 |
a date range to confine output to). Pass \code{"ask"} to start an |
| 94 |
application that helps guide parameter configuration.} |
| 95 |
|
| 96 |
\item{knit_meta}{(This option is reserved for expert use.) Metadata |
| 97 |
generated by \pkg{knitr}.} |
| 98 |
|
| 99 |
\item{envir}{The environment in which the code chunks are to be evaluated |
| 100 |
during knitting (can use \code{\link{new.env}()} to guarantee an empty new |
| 101 |
environment).} |
| 102 |
|
| 103 |
\item{run_pandoc}{An option for whether to run pandoc to convert Markdown |
| 104 |
output.} |
| 105 |
|
| 106 |
\item{quiet}{An option to suppress printing during rendering from knitr, |
| 107 |
pandoc command line and others. To only suppress printing of the last |
| 108 |
"Output created: " message, you can set \code{rmarkdown.render.message} to |
| 109 |
\code{FALSE}} |
| 110 |
|
| 111 |
\item{encoding}{Ignored. The encoding is always assumed to be UTF-8.} |
| 112 |
} |
| 113 |
\value{ |
| 114 |
When \code{run_pandoc = TRUE}, the compiled document is written into |
| 115 |
the output file, and the path of the output file is returned. When |
| 116 |
\code{run_pandoc = FALSE}, the path of the Markdown output file, with |
| 117 |
attributes \code{knit_meta} (the \pkg{knitr} meta data collected from code |
| 118 |
chunks) and \code{intermediates} (the intermediate files/directories |
| 119 |
generated by \code{render()}). |
| 120 |
} |
| 121 |
\description{ |
| 122 |
Render the input file to the specified output format using pandoc. If the |
| 123 |
input requires knitting then \code{\link[knitr:knit]{knit}} is called prior |
| 124 |
to pandoc. |
| 125 |
} |
| 126 |
\details{ |
| 127 |
Note that the \pkg{knitr} \code{error} option is set to \code{FALSE} during |
| 128 |
rendering (which is different from the \pkg{knitr} default value of |
| 129 |
\code{TRUE}). |
| 130 |
|
| 131 |
For additional details on rendering R scripts see |
| 132 |
\link[=compile_notebook]{Compiling R scripts to a notebook}. |
| 133 |
|
| 134 |
If no \code{output_format} parameter is specified then the output format is |
| 135 |
read from the YAML front-matter of the input file. For example, the |
| 136 |
following YAML would yield a PDF document: |
| 137 |
|
| 138 |
\preformatted{ |
| 139 |
output: pdf_document |
| 140 |
} |
| 141 |
|
| 142 |
Additional format options can also be specified in metadata. For example: |
| 143 |
|
| 144 |
\preformatted{ |
| 145 |
output: |
| 146 |
pdf_document: |
| 147 |
toc: true |
| 148 |
highlight: zenburn |
| 149 |
} |
| 150 |
|
| 151 |
Multiple formats can be specified in metadata. If no \code{output_format} |
| 152 |
is passed to \code{render} then the first one defined will be used: |
| 153 |
|
| 154 |
\preformatted{ |
| 155 |
output: |
| 156 |
pdf_document: |
| 157 |
toc: true |
| 158 |
highlight: zenburn |
| 159 |
html_document: |
| 160 |
toc: true |
| 161 |
theme: united |
| 162 |
} |
| 163 |
|
| 164 |
Formats specified in metadata can be any one of the built in formats (e.g. |
| 165 |
\code{\link{html_document}}, \code{\link{pdf_document}}) or a format defined |
| 166 |
in another package (e.g. \code{pkg::custom_format}). |
| 167 |
|
| 168 |
If there is no format defined in the YAML then |
| 169 |
\code{\link{html_document}} will be used. |
| 170 |
} |
| 171 |
\section{R Markdown}{ |
| 172 |
|
| 173 |
R Markdown supports all of the base pandoc markdown features as well as some |
| 174 |
optional features for compatibility with GitHub Flavored Markdown (which |
| 175 |
previous versions of R Markdown were based on). See |
| 176 |
\code{\link{rmarkdown_format}} for details. |
| 177 |
} |
| 178 |
|
| 179 |
\examples{ |
| 180 |
\dontrun{ |
| 181 |
library(rmarkdown) |
| 182 |
|
| 183 |
# Render the default (first) format defined in the file |
| 184 |
render("input.Rmd") |
| 185 |
|
| 186 |
# Render all formats defined in the file |
| 187 |
render("input.Rmd", "all") |
| 188 |
|
| 189 |
# Render a single format, using parameters for \code{html_document} from |
| 190 |
# the YAML header parameters. |
| 191 |
render("input.Rmd", "html_document") |
| 192 |
|
| 193 |
# Render a single format, ignoring parameters for \code{html_document} in |
| 194 |
# the YAML header. Any parameters not passed as arguments to |
| 195 |
# \code{html_document()} will be assigned to their default values, regardless |
| 196 |
# of anything in the YAML header |
| 197 |
render("input.Rmd", html_document(toc = TRUE, toc_depth = 2)) |
| 198 |
|
| 199 |
# Render multiple formats |
| 200 |
render("input.Rmd", c("html_document", "pdf_document")) |
| 201 |
} |
| 202 |
} |
| 203 |
\seealso{ |
| 204 |
\link[knitr:knit]{knit}, \link{output_format}, |
| 205 |
\url{https://pandoc.org} |
| 206 |
} |