Debian Codegraph @

man/raw_output.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/utils.R
3 \name{extract_raw_output}
4 \alias{extract_raw_output}
5 \alias{restore_raw_output}
6 \alias{raw_output}
7 \title{Mark character strings as raw output that should not be converted}
8 \usage{
9 extract_raw_output(text, markers = raw_markers)
10
11 restore_raw_output(text, chunks, markers = raw_markers)
12
13 raw_output(x, markers = raw_markers, ...)
14 }
15 \arguments{
16 \item{text}{For \code{extract_raw_output()}, the content of the input file
17 (e.g. Markdown); for \code{restore_raw_output()}, the content of the output
18 file (e.g. HTML generated by Pandoc from Markdown).}
19
20 \item{markers}{A length-2 character vector to be used to wrap \code{x};
21 see \code{knitr:::raw_markers} for the default value.}
22
23 \item{chunks}{A named character vector returned from
24 \code{extract_raw_output()}.}
25
26 \item{x}{The character vector to be protected.}
27
28 \item{...}{Arguments to be passed to \code{\link{asis_output}()}.}
29 }
30 \value{
31 For \code{extract_raw_output()}, a list of two components:
32 \code{value} (the \code{text} with raw output replaced by MD5 digests) and
33 \code{chunks} (a named character vector, of which the names are MD5 digests
34 and values are the raw output). For \code{restore_raw_output()}, the
35 restored \code{text}.
36 }
37 \description{
38 These functions provide a mechanism to protect the character output of R code
39 chunks. The output is annotated with special markers in \code{raw_output};
40 \code{extract_raw_output()} will extract raw output wrapped in the markers,
41 and replace the raw output with its MD5 digest; \code{restore_raw_output()}
42 will restore the MD5 digest with the original raw output.
43 }
44 \details{
45 This mechanism is designed primarily for R Markdown pre/post-processors. In
46 an R code chunk, you generate \code{raw_output()} to the Markdown output. In
47 the pre-processor, you can \code{extract_raw_output()} from the Markdown
48 file, store the raw output and MD5 digests, and remove the actual raw output
49 from Markdown so Pandoc will never see it. In the post-processor, you can
50 read the Pandoc output (e.g., an HTML or RTF file), and restore the raw
51 output.
52 }
53 \examples{
54 library(knitr)
55 out = c("*hello*", raw_output("<special>content</special> *protect* me!"),
56 "*world*")
57 pre = extract_raw_output(out)
58 str(pre)
59 pre$value = gsub("[*]([^*]+)[*]", "<em>\\\\1</em>",
60 pre$value) # think this as Pandoc conversion
61 pre$value
62 # raw output was protected from the conversion
63 # (e.g. *protect* was not converted)
64 restore_raw_output(pre$value, pre$chunks)
65 }