epoxy {epoxy} | R Documentation |
Epoxy string interpolation
Description
These functions power the knitr chunk engines and are wrappers around
glue::glue()
, with a few extra conveniences provided by epoxy.
-
epoxy()
is superglue::glue()
. -
epoxy_html()
is superglue::glue()
with HTML-specific defaults. -
epoxy_latex()
is superglue::glue()
with LaTeX-specific defaults.
Each of these functions can be called directly or used as a knitr chunk engine where the chunk text is handled as if it were a string passed into the function version. When used as a knitr chunk engine, the function arguments can be passed in as chunk options.
All of epoxy()
, epoxy_html()
and epoxy_latex()
use
epoxy_transform_inline()
by default. This transformer brings a concise
inline-formatting syntax that you can read more about in
?epoxy_transform_inline
.
epoxy_html()
also includes an inline transformation syntax that makes it
easier to wrap the expression text in HTML elements with a specific ID or
a set of classes. Learn more about this syntax in ?epoxy_transform_html
.
Usage
epoxy(
...,
.data = NULL,
.sep = "",
.envir = parent.frame(),
.open = "{",
.close = "}",
.na = "",
.null = "",
.comment = character(),
.literal = FALSE,
.trim = FALSE,
.transformer = NULL,
.collapse = NULL,
.style = lifecycle::deprecated()
)
epoxy_html(
...,
.data = NULL,
.sep = "",
.envir = parent.frame(),
.open = "{{",
.close = "}}",
.na = "",
.null = "",
.comment = "",
.literal = FALSE,
.trim = FALSE,
.transformer = NULL,
.collapse = NULL
)
epoxy_latex(
...,
.data = NULL,
.sep = "",
.envir = parent.frame(),
.open = "<<",
.close = ">>",
.na = "",
.null = "",
.comment = "",
.literal = FALSE,
.trim = FALSE,
.transformer = NULL,
.collapse = NULL
)
Arguments
... |
[ |
.data |
A data set |
.sep |
[ |
.envir |
[ |
.open |
[ |
.close |
[ |
.na |
[ |
.null |
[ |
.comment |
[ |
.literal |
[ |
.trim |
[ |
.transformer |
A transformer function or transformer chain created with
In epoxy, you'll most likely want to use the defaults or consult
|
.collapse |
A character string used to collapse a vector result into a
single value. If |
.style |
Value
Returns a transformed string, using glue::glue()
but with the
additional transformers provided to the .transformer
argument of
epoxy()
.
See Also
-
use_epoxy_knitr_engines()
for knitr engines powered by these epoxy functions. -
epoxy_mustache()
for more powerful templating needs when you don't need epoxy's inline formatting syntax.
Examples
movie <- bechdel[1, ]
movies <- bechdel[2:4, ]
# A basic example with a single row of data
epoxy("{.emph movie$title} ({movie$year}) was directed by {movie$director}.")
# Or vectorized over multiple rows of data
epoxy("* {.emph movies$title} ({movies$year}) was directed by {movies$director}.")
# You can provide the data frame to `.data` to avoid repeating `data$`
epoxy("{.emph title} ({year}) was directed by {director}.", .data = movie)
epoxy("* {.emph title} ({year}) was directed by {director}.", .data = movies)
# Inline transformers can be nested
epoxy("I'd be happy to watch {.or {.italic title}}.", .data = movies)
epoxy("They were directed by {.and {.bold director}}.", .data = movies)
# Learn more about inline transformers in ?epoxy_transform_inline
epoxy("The budget for {.emph title} was {.dollar budget}.", .data = movie)
# --------- HTML and LaTeX variants ---------
# There are also HTML and LaTeX variants of epoxy.
# Each uses default options that are most natural for the format.
# epoxy_html() uses `{{ expr }}` for delimiters
epoxy_html("I'd be happy to watch {{ title }}.", .data = movie)
# It also supports an HTML transformer syntax
epoxy_html("I'd be happy to watch {{em.movie-title title}}.", .data = movie)
# Or use the inline transformer syntax, which uses `@` instead of `.` in HTML
epoxy_html("I'd be happy to watch {{@or {{@emph title}} }}.", .data = movies)
# epoxy_latex() uses `<< expr >>` for delimiters
epoxy_latex("I'd be happy to watch <<.or <<.emph title >> >>.", .data = movies)