| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/fuse.R, R/mark.R |
| 3 |
\name{fuse} |
| 4 |
\alias{fuse} |
| 5 |
\alias{fiss} |
| 6 |
\alias{mark} |
| 7 |
\title{Render Markdown, R Markdown, and R scripts} |
| 8 |
\usage{ |
| 9 |
fuse(input, output = NULL, text = NULL, envir = parent.frame(), quiet = FALSE) |
| 10 |
|
| 11 |
fiss(input, output = ".R", text = NULL) |
| 12 |
|
| 13 |
mark(input, output = NULL, text = NULL, options = NULL, meta = list()) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{input}{A character vector to provide the input file path or text. If |
| 17 |
not provided, the \code{text} argument must be provided instead. The \code{input} |
| 18 |
vector will be treated as a file path if it is a single string, and points |
| 19 |
to an existing file or has a filename extension. In other cases, the vector |
| 20 |
will be treated as the \code{text} argument input. To avoid ambiguity, if a |
| 21 |
string should be treated as \code{text} input when it happens to be an existing |
| 22 |
file path or has an extension, wrap it in \code{\link[=I]{I()}}, or simply use the \code{text} |
| 23 |
argument instead.} |
| 24 |
|
| 25 |
\item{output}{An output file path or a filename extension (e.g., \code{.html}, |
| 26 |
\code{.tex}, \code{.xml}, \code{.man}, \code{.markdown}, or \code{.txt}). In the latter case, the |
| 27 |
output file path will use the extension on the same base filename as the |
| 28 |
input file if the \code{input} is a file. If \code{output} is not character (e.g., |
| 29 |
\code{NA}), the results will be returned as a character vector instead of being |
| 30 |
written to a file. If \code{output} is \code{NULL} or an extension, and the input is |
| 31 |
a file path, the output file path will have the same base name as the input |
| 32 |
file, with an extension corresponding to the output format. The output |
| 33 |
format is retrieved from the first value in the \code{output} field of the YAML |
| 34 |
metadata of the \code{input} (e.g., \code{html} will generate HTML output). The |
| 35 |
\code{output} argument can also take an output format name (possible values are |
| 36 |
\code{html}, \code{latex}, \code{xml}, \code{man}, \code{commonmark}, and \code{text}). If no output |
| 37 |
format is detected or provided, the default is HTML.} |
| 38 |
|
| 39 |
\item{text}{A character vector as the text input. By default, it is read from |
| 40 |
the \code{input} file if provided.} |
| 41 |
|
| 42 |
\item{envir}{An environment in which the code is to be evaluated. It can be |
| 43 |
accessed via \code{\link[=fuse_env]{fuse_env()}} inside \code{\link[=fuse]{fuse()}}.} |
| 44 |
|
| 45 |
\item{quiet}{If \code{TRUE}, do not show the progress bar. If \code{FALSE}, the |
| 46 |
progress bar will be shown after a number of seconds, which can be set via |
| 47 |
a global \link[=options]{option} \code{litedown.progress.delay} (the default is \code{2}). |
| 48 |
THe progress bar output can be set via a global option |
| 49 |
\code{litedown.progress.output} (the default is \code{\link[=stderr]{stderr()}}).} |
| 50 |
|
| 51 |
\item{options}{Options to be passed to the renderer. See \code{\link[=markdown_options]{markdown_options()}} |
| 52 |
for details. This argument can take either a character vector of the form |
| 53 |
\code{"+option1 option2-option3"} (use \code{+} or a space to enable an option, and |
| 54 |
\code{-} to disable an option), or a list of the form \code{list(option1 = value1, option2 = value2, ...)}. A string \code{"+option1"} is equivalent to |
| 55 |
\code{list(option1 = TRUE)}, and \code{"-option2"} means \code{list(option2 = FALSE)}. |
| 56 |
Options that do not take logical values must be specified via a list, e.g., |
| 57 |
\code{list(width = 30)}.} |
| 58 |
|
| 59 |
\item{meta}{A named list of metadata. Elements in the metadata will be used |
| 60 |
to fill out the template by their names and values, e.g., \code{list(title = ...)} will replace the \verb{$title$} variable in the template. See the Section |
| 61 |
\dQuote{YAML metadata} \href{https://yihui.org/litedown/#sec:yaml-metadata}{in the documentation} for supported |
| 62 |
variables.} |
| 63 |
} |
| 64 |
\value{ |
| 65 |
The output file path if output is written to a file, otherwise a |
| 66 |
character vector of the rendered output (wrapped in \code{\link[xfun:raw_string]{xfun::raw_string()}} |
| 67 |
for clearer printing). |
| 68 |
} |
| 69 |
\description{ |
| 70 |
The function \code{fuse()} runs code from code chunks and inline code |
| 71 |
expressions in R Markdown, interweaves the results with the rest of text in |
| 72 |
the input to intermediate Markdown output (which is similar to what |
| 73 |
\code{knitr::knit()} does), and renders the Markdown output through \code{mark()} to |
| 74 |
the final output format, such as HTML or LaTeX (similar to |
| 75 |
\code{rmarkdown::render()}). It also works on R scripts in a way similar to |
| 76 |
\code{knitr::spin()}. The function \code{fiss()} extracts code from the input, and is |
| 77 |
similar to \code{knitr::purl()}. |
| 78 |
|
| 79 |
The function \code{mark()} renders Markdown to an output format via the |
| 80 |
\pkg{commonmark} package. |
| 81 |
} |
| 82 |
\note{ |
| 83 |
For \code{fuse()}, you can generate the intermediate Markdown output via |
| 84 |
\code{output = '.md'} or \code{output = 'markdown'} without further calling \code{mark()}. |
| 85 |
} |
| 86 |
\examples{ |
| 87 |
library(litedown) |
| 88 |
doc = c("```{r}", "1 + 1", "```", "", "$\\\\pi$ = `{r} pi`.") |
| 89 |
fuse(doc) |
| 90 |
fuse(doc, ".tex") |
| 91 |
fiss(doc) |
| 92 |
|
| 93 |
mark(c("Hello _World_!", "", "Welcome to **litedown**.")) |
| 94 |
# if input appears to be a file path but should be treated as text, use I() |
| 95 |
mark(I("This is *not* a file.md")) |
| 96 |
# that's equivalent to |
| 97 |
mark(text = "This is *not* a file.md") |
| 98 |
|
| 99 |
# output to a file |
| 100 |
(mark("_Hello_, **World**!", output = tempfile())) |
| 101 |
|
| 102 |
# convert to other formats |
| 103 |
mark("Hello _World_!", ".tex") |
| 104 |
mark("Hello _**`World`**_!", "xml") |
| 105 |
mark("Hello _**`World`**_!", "text") |
| 106 |
} |
| 107 |
\seealso{ |
| 108 |
\code{\link[=sieve]{sieve()}}, for the syntax of R scripts to be passed to \code{\link[=fuse]{fuse()}}. |
| 109 |
|
| 110 |
The spec of GitHub Flavored Markdown: |
| 111 |
\url{https://github.github.com/gfm/} |
| 112 |
} |