Skip to contents

The functions power the knitr chunk engines and are wrappers around glue::glue(), with a few extra conveniences provided by epoxy.

Usage

epoxy(
  ...,
  .data = NULL,
  .style = NULL,
  .sep = "",
  .envir = parent.frame(),
  .open = "{",
  .close = "}",
  .na = "",
  .null = "",
  .comment = "#",
  .literal = FALSE,
  .trim = FALSE,
  .transformer = NULL
)

epoxy_html(
  ...,
  .data = NULL,
  .style = c("collapse", "format", "html"),
  .sep = "",
  .envir = parent.frame(),
  .open = "{{",
  .close = "}}",
  .na = "",
  .null = "",
  .comment = "",
  .literal = FALSE,
  .trim = FALSE,
  .transformer = NULL
)

epoxy_latex(
  ...,
  .data = NULL,
  .style = NULL,
  .sep = "",
  .envir = parent.frame(),
  .open = "<",
  .close = ">",
  .na = "",
  .null = "",
  .comment = "#",
  .literal = FALSE,
  .trim = FALSE,
  .transformer = NULL
)

Arguments

...

[expressions]
Unnamed arguments are taken to be expression string(s) to format. Multiple inputs are concatenated together before formatting. Named arguments are taken to be temporary variables available for substitution.

.data

A data set

.style

For epoxy_style()

.sep

[character(1): ‘""’]
Separator used to separate elements.

.envir

[environment: parent.frame()]
Environment to evaluate each expression in. Expressions are evaluated from left to right. If .x is an environment, the expressions are evaluated in that environment and .envir is ignored. If NULL is passed, it is equivalent to emptyenv().

.open

[character(1): ‘\{’]
The opening delimiter. Doubling the full delimiter escapes it.

.close

[character(1): ‘\}’]
The closing delimiter. Doubling the full delimiter escapes it.

.na

[character(1): ‘NA’]
Value to replace NA values with. If NULL missing values are propagated, that is an NA result will cause NA output. Otherwise the value is replaced by the value of .na.

.null

[character(1): ‘character()’]
Value to replace NULL values with. If character() whole output is character(). If NULL all NULL values are dropped (as in paste0()). Otherwise the value is replaced by the value of .null.

.comment

[character(1): ‘#’]
Value to use as the comment character.

.literal

[boolean(1): ‘FALSE’]
Whether to treat single or double quotes, backticks, and comments as regular characters (vs. as syntactic elements), when parsing the expression string. Setting .literal = TRUE probably only makes sense in combination with a custom .transformer, as is the case with glue_col(). Regard this argument (especially, its name) as experimental.

.trim

[logical(1): ‘TRUE’]
Whether to trim the input template with trim() or not.

.transformer

[function]
A function taking three parameters code, envir and data used to transform the output of each block before, during, or after evaluation. For example transformers see vignette("transformers").

Functions

  • epoxy: super glue()

  • epoxy_html: super glue() for HTML

  • epoxy_latex: super glue() for LaTeX

Examples

movie <- bechdel[1, ]
movies <- bechdel[2:4, ]

epoxy("*{movie$title}* ({movie$year}) was directed by {movie$director}.")
#> *Inception* (2010) was directed by Christopher Nolan.
epoxy("- *{movies$title}* ({movies$year}) was directed by {movies$director}.")
#> - *Back to the Future Part II* (1989) was directed by Robert Zemeckis.
#> - *The Simpsons Movie* (2007) was directed by David Silverman.
#> - *Another Year* (2010) was directed by Mike Leigh.

epoxy("*{title}* ({year}) was directed by {director}.", .data = movie)
#> *Inception* (2010) was directed by Christopher Nolan.
epoxy("- *{title}* ({year}) was directed by {director}.", .data = movies)
#> - *Back to the Future Part II* (1989) was directed by Robert Zemeckis.
#> - *The Simpsons Movie* (2007) was directed by David Silverman.
#> - *Another Year* (2010) was directed by Mike Leigh.

epoxy(
  "{title} ({year}) was directed by {director}.",
  .data = movie,
  .style = "bold"
)
#> **Inception** (**2010**) was directed by **Christopher Nolan**.

epoxy(
  "I'd be happy to watch { title| }.",
  .data = movies,
  .style = c("italic", "collapse")
)
#> I'd be happy to watch _Back to the Future Part II_, _The Simpsons Movie_ or _Another Year_.

epoxy(
  "They were directed by { director& }.",
  .data = movies,
  .style = c("collapse", "bold")
)
#> They were directed by **Robert Zemeckis, David Silverman and Mike Leigh**.

epoxy("The budget for *{title}* was {fmt(budget, '$')}.", .data = movie)
#> The budget for *Inception* was $160,000,000.

epoxy_html(
  "I'd be happy to watch {{ title| }}.",
  .data = movies,
  .style = c("italic", "collapse")
)
#> I'd be happy to watch <em>Back to the Future Part II</em>, <em>The Simpsons Movie</em> or <em>Another Year</em>.

epoxy_latex(
  "I'd be happy to watch < title| >.",
  .data = movies,
  .style = c("italic", "collapse")
)
#> I'd be happy to watch \emph{Back to the Future Part II}, \emph{The Simpsons Movie} or \emph{Another Year}.