| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/output_format.R |
| 3 |
\name{output_format_dependency} |
| 4 |
\alias{output_format_dependency} |
| 5 |
\title{Define and merge an R Markdown's output format dependency} |
| 6 |
\usage{ |
| 7 |
output_format_dependency( |
| 8 |
name, |
| 9 |
pandoc = list(), |
| 10 |
pre_processor = NULL, |
| 11 |
post_processor = NULL, |
| 12 |
file_scope = NULL, |
| 13 |
on_exit = NULL |
| 14 |
) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{name}{A dependency name. If some dependencies share the same name, |
| 18 |
then only the first one will be merged to the output format.} |
| 19 |
|
| 20 |
\item{pandoc}{Pandoc options for an output format (see |
| 21 |
\code{\link{pandoc_options}})} |
| 22 |
|
| 23 |
\item{pre_processor}{An optional pre-processor function that receives the |
| 24 |
\code{metadata}, \code{input_file}, \code{runtime}, \code{knit_meta}, |
| 25 |
\code{files_dir}, and \code{output_dir} and can return additional arguments |
| 26 |
to pass to pandoc.} |
| 27 |
|
| 28 |
\item{post_processor}{An optional post-processor function that receives the |
| 29 |
\code{metadata}, \code{input_file}, \code{output_file}, \code{clean}, and |
| 30 |
\code{verbose} parameters, and can return an alternative |
| 31 |
\code{output_file}.} |
| 32 |
|
| 33 |
\item{file_scope}{A function that will split markdown input to pandoc into |
| 34 |
multiple named files. This is useful when the caller has concatenated a set |
| 35 |
of Rmd files together (as \pkg{bookdown} does), and those files may need to |
| 36 |
processed by pandoc using the \code{--file-scope} option. The first |
| 37 |
argument is input file paths and the second is \code{NULL} or current file |
| 38 |
scope which is a named list of files w/ \code{name} and \code{content} for |
| 39 |
each file. The return is the new file scope. Also, the arguments should |
| 40 |
include \code{...} for the future extensions.} |
| 41 |
|
| 42 |
\item{on_exit}{A function to call when \code{rmarkdown::render()} finishes |
| 43 |
execution (as registered with a \code{\link{on.exit}} handler).} |
| 44 |
} |
| 45 |
\value{ |
| 46 |
An list of arguments with the "rmd_dependency" class. |
| 47 |
} |
| 48 |
\description{ |
| 49 |
Define and merge a dependency such as pre/post-processors from within |
| 50 |
chunks. The merge happens explicitly when a list of dependencies are |
| 51 |
passed to \code{knitr::knit_meta_add()} or implicitly when a dependency |
| 52 |
is \code{knitr::knit_print}ed. Defining a function that does the former is |
| 53 |
the best way for package developers to share the dependency. On the |
| 54 |
contrary, the latter is useful to declare a document-specific dependency. |
| 55 |
This function shares some arguments with \code{\link{output_format}}, |
| 56 |
but lacks the others because dependency is resolved after \code{post_knit} |
| 57 |
and before \code{pre_processor}. |
| 58 |
} |
| 59 |
\examples{ |
| 60 |
# Implicitly add lua filters from within a chunk |
| 61 |
# This relies on (implicit) printing of the dependency in a chunk via |
| 62 |
# knitr::knit_print()` |
| 63 |
output_format_dependency( |
| 64 |
"lua_filter1", |
| 65 |
pandoc = list(lua_filters = "example1.lua") |
| 66 |
) |
| 67 |
|
| 68 |
# Explicitly add lua filters from within a chunk |
| 69 |
knitr::knit_meta_add(list(output_format_dependency( |
| 70 |
"lua_filter2", |
| 71 |
pandoc = list(lua_filters = "example2.lua") |
| 72 |
))) |
| 73 |
|
| 74 |
# List the available dependencies |
| 75 |
# Note that the list may include dependencies with duplicated names. In that |
| 76 |
# case, the first one is merged to the output format and the others are |
| 77 |
# discarded. |
| 78 |
str(knitr::knit_meta("output_format_dependency", clean = FALSE)) |
| 79 |
|
| 80 |
} |