Learn R Programming

inlmisc (version 0.3.2)

ReplaceInTemplate: Replace Values in a Template Text

Description

This function replaces keys within special markups in a template text with specified values. Pieces of R code can be put into the markups of the template text, and are evaluated during the replacement.

Usage

ReplaceInTemplate(text, replacement)

Arguments

text

'character'. Vector of character strings, that is the template text.

replacement

'list'. Values to replace in text.

Value

Returns a vector of character strings after key replacement.

Details

Keys are enclosed into markups of the form $(KEY) and @{CODE}.

References

This code was derived from the sensitivity::template.replace function, accessed on Feb 6, 2015.

See Also

SummariseBudget

Examples

Run this code
# NOT RUN {
text <- c("Hello $(name)!", "$(a) + $(b) = @{$(a) + $(b)}",
          "pi = @{format(pi, digits = 5)}")
replacement <- list(name = "world", a = 1, b = 2)
cat(ReplaceInTemplate(text, replacement), sep = "\n")

# }

Run the code above in your browser using DataLab