glue | R Documentation |
Inputs enclosed by braces (e.g. {name}
) are looked up in the provided
environment (akin to calling get()
). Single braces can be escaped by
doubling them up. Variables are recycled to the length of the largest one.
glue()
operates on the string as is.
glut()
will trim
the input prior to glueing.
glue(x, env = parent.frame())
glut(x, env = parent.frame())
x |
|
env |
Where to look up the embraced input. Can be an environment or a list-like object that will be converted in the
underlying function via |
A character
object.
glue::glue_safe()
and glue::glue_data_safe()
on which which this
function is an evolution.
name <- "Fred"
age <- 50
cat(glue("My name is {name} and my age next year is {age}"))
# glut first trims the output
anniversary <- as.Date("1991-10-12")
cat(glut("
My name is {name},
my age next year is {age},
my anniversary is {anniversary}.
"))
# single braces can be inserted by doubling them
glue("My name is {name}, not {{name}}.")
# List like objects can be used in place of an environment
dat <- cbind(car = rownames(mtcars), mtcars)
glue("{car} does {mpg} mpg.", dat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.