Learn R Programming

lares (version 5.1.0)

glued: Interpolate a string [glue wrapper]

Description

Format and interpolate a string using a glue wrapper. Allows simple operations, NULL values as input, and interactions with internal (created within glued) and external (environment) objects.

Usage

glued(..., .sep = "", empty_lines = "keep", .envir = parent.frame())

Arguments

...

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

.sep

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

empty_lines

Character. Set to "keep" to keep or "drop" to drop empty lines.

.envir

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

Value

Same as input but transformed (glued).

Examples

Run this code
# NOT RUN {
name <- "Bernardo"
age <- 29
anniversary <- as.Date("2016-04-30")
glued("
  My name is {name},
  my age next year will be {age + 1},
  and I got married on {format(anniversary, '%A, %B %d, %Y')}.")

# Single braces can be inserted by doubling them
glued("My name is {name}, not {{name}}.")

# You can also used named arguments
glued(
  "Her name is {name}, ",
  "and her age next year will be {age + 1}.",
  name = "Maru",
  age = 6
)

# And run operations with memories (beware!)
glued("My name, {name}, has {n <- nchar(name); n} characters.
       If we multiply by ten, we'll have {10 * n} characters!")

# If you pass a vector, the operation will be repeated for each element
glued("Here's the value #{1:3}")
# }

Run the code above in your browser using DataLab