ReplaceInTemplate: Replace Values in a Template Text

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/ReplaceInTemplate.R

Description

Replace 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

1
ReplaceInTemplate(text, replacement = list())

Arguments

text

'character' vector. Template text

replacement

'list'. Values to replace in text.

Details

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

Value

A 'character' vector of strings after key replacement.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

References

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

See Also

SummariseBudget

Examples

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

inlmisc documentation built on Jan. 25, 2022, 1:14 a.m.