str_glue | R Documentation |
These functions are wrappers around glue::glue()
and glue::glue_data()
,
which provide a powerful and elegant syntax for interpolating strings
with {}
.
These wrappers provide a small set of the full options. Use glue()
and
glue_data()
directly from glue for more control.
str_glue(..., .sep = "", .envir = parent.frame())
str_glue_data(.x, ..., .sep = "", .envir = parent.frame(), .na = "NA")
... |
[ |
.sep |
[ |
.envir |
[ |
.x |
[ |
.na |
[ |
A character vector with same length as the longest input.
name <- "Fred"
age <- 50
anniversary <- as.Date("1991-10-12")
str_glue(
"My name is {name}, ",
"my age next year is {age + 1}, ",
"and my anniversary is {format(anniversary, '%A, %B %d, %Y')}."
)
# single braces can be inserted by doubling them
str_glue("My name is {name}, not {{name}}.")
# You can also used named arguments
str_glue(
"My name is {name}, ",
"and my age next year is {age + 1}.",
name = "Joe",
age = 40
)
# `str_glue_data()` is useful in data pipelines
mtcars %>% str_glue_data("{rownames(.)} has {hp} hp")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.