Format and interpolate a string

Expressions enclosed by braces will be evaluated as R code. Single braces can be inserted by doubling them.

glue_data(.x, ..., .sep = "", .envir = parent.frame(), .open = "{",
  .close = "}")

glue(..., .sep = "", .envir = parent.frame(), .open = "{", .close = "}")


[listish] An environment, list or data frame used to lookup values.


[expressions] Expressions string(s) to format, multiple inputs are concatenated together before formatting.


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


[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.


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


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

See Also and upon which this is based.

  • glue
  • glue_data
  • glue
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 also be supplied
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_data()` is useful in magrittr pipes
mtcars %>% glue_data("{rownames(.)} has {hp} hp")

# Alternative delimiters can also be used if needed
one <- "1"
glue("The value of $e^{2\\pi i}$ is $<<one>>$.", .open = "<<", .close = ">>")
Documentation reproduced from package glue, version 1.1.1, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.