glue

0th

Percentile

Format and interpolate a string

Expressions enclosed by braces will be evaluated as R code. Single braces can be inserted by doubling them. The inputs are not vectorized.

Usage
glue_data(.x, ..., .sep = "", .envir = parent.frame())
to_data(.x, ..., .sep = "", .envir = parent.frame())
glue(..., .sep = "", .envir = parent.frame())
to(..., .sep = "", .envir = parent.frame())
Arguments
.x
An environment, list or data frame.
...
String(s) to format, multiple inputs are concatenated together before formatting.
.sep
Separator used to separate elements.
.envir
Environment to evaluate each expression in. Expressions are evaluated from left to right.
See Also

https://www.python.org/dev/peps/pep-0498/ upon which this is based.

Aliases
  • glue
  • glue_data
  • to_data
  • glue
  • to
Examples
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
library(magrittr)
mtcars %>% glue_data("{rownames(.)} has {hp} hp")
Documentation reproduced from package glue, version 0.0.0.9000, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.