glue | R Documentation |
Expressions enclosed by braces will be evaluated as R code. Long strings are broken by line and concatenated together. Leading whitespace and blank lines from the first and last lines are automatically trimmed.
glue_data(
.x,
...,
.sep = "",
.envir = parent.frame(),
.open = "{",
.close = "}",
.na = "NA",
.null = character(),
.comment = "#",
.literal = FALSE,
.transformer = identity_transformer,
.trim = TRUE
)
glue(
...,
.sep = "",
.envir = parent.frame(),
.open = "{",
.close = "}",
.na = "NA",
.null = character(),
.comment = "#",
.literal = FALSE,
.transformer = identity_transformer,
.trim = TRUE
)
.x |
[ |
... |
[ For |
.sep |
[ |
.envir |
[ |
.open |
[ |
.close |
[ |
.na |
[ |
.null |
[ |
.comment |
[ |
.literal |
[ |
.transformer |
[ |
.trim |
[ |
A glue object, as created by as_glue()
.
https://www.python.org/dev/peps/pep-0498/ and https://www.python.org/dev/peps/pep-0257/ upon which this is based.
name <- "Fred"
age <- 50
anniversary <- as.Date("1991-10-12")
glue('My name is {name},',
'my age next year is {age + 1},',
'my anniversary is {format(anniversary, "%A, %B %d, %Y")}.')
# single braces can be inserted by doubling them
glue("My name is {name}, not {{name}}.")
# Named arguments can be used to assign temporary variables.
glue('My name is {name},',
' my age next year is {age + 1},',
' my anniversary is {format(anniversary, "%A, %B %d, %Y")}.',
name = "Joe",
age = 40,
anniversary = as.Date("2001-10-12"))
# `glue()` can also be used in user defined functions
intro <- function(name, profession, country){
glue("My name is {name}, a {profession}, from {country}")
}
intro("Shelmith", "Senior Data Analyst", "Kenya")
intro("Cate", "Data Scientist", "Kenya")
# `glue_data()` is useful in magrittr pipes
if (require(magrittr)) {
mtcars %>% glue_data("{rownames(.)} has {hp} hp")
# Or within dplyr pipelines
if (require(dplyr)) {
head(iris) %>%
mutate(description = glue("This {Species} has a petal length of {Petal.Length}"))
}}
# Alternative delimiters can also be used if needed
one <- "1"
glue("The value of $e^{2\\pi i}$ is $<<one>>$.", .open = "<<", .close = ">>")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.