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]
Unnamed arguments are taken to be expression string(s) to format. Multiple inputs are concatenated together before formatting. Named arguments are taken to be temporary variables available for substitution.For
glue_data(), elements in...override the values in.x.- .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.xis an environment, the expressions are evaluated in that environment and.enviris ignored. IfNULLis passed, it is equivalent toemptyenv().
See also
Other Tools:
autoline(),
bind_files(),
bring_api(),
chr2num(),
db_download(),
db_upload(),
dont_sleep(),
export_plot(),
export_results(),
files_functions(),
font_exists(),
formatColoured(),
formatHTML(),
grepm(),
h2o_selectmodel(),
haveInternet(),
image_metadata(),
importxlsx(),
ip_data(),
json2vector(),
list_cats(),
listfiles(),
mail_send(),
markdown2df(),
move_files(),
msplit(),
myip(),
quiet(),
read.file(),
statusbar(),
tic(),
try_require(),
updateLares(),
warnifnot(),
what_size()
Examples
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')}.")
#> My name is Bernardo,
#> my age next year will be 30,
#> and I got married on Saturday, April 30, 2016.
# Single braces can be inserted by doubling them
glued("My name is {name}, not {{name}}.")
#> My name is Bernardo, 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
)
#> Her name is Maru, and her age next year will be 7.
# 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!")
#> My name, Bernardo, has 8 characters.
#> If we multiply by ten, we'll have 80 characters!
# If you pass a vector, the operation will be repeated for each element
glued("Here's the value #{1:3}")
#> Here's the value #1
#> Here's the value #2
#> Here's the value #3
