text_expand: Evaluate expressions in curly brackets inside strings

View source: R/text_expand.R

text_expandR Documentation

Evaluate expressions in curly brackets inside strings

Description

text_expand is simple string interpolation function. It searches in its arguments expressions in curly brackets {expr}, evaluate them and substitute with the result of evaluation. See examples.

Usage

text_expand(..., delim = c("\\{", "\\}"))

Arguments

...

character vectors

delim

character vector of length 2 - pair of opening and closing delimiters for the templating tags. By default it is curly brackets. Note that delim will be used in the perl-style regular expression so you need to escape special characters, e. g. use "\\{" instead of "{".

Value

Vector of characters

Examples

i = 1:5
text_expand("q{i}")

i = 1:3
j = 1:3
text_expand("q1_{i}_{j}")

data(iris)
text_expand("'iris' has {nrow(iris)} rows.")

maditr documentation built on April 2, 2022, 5:05 p.m.