Light-weight template filling: replace placeholders in a string by values.
fill_in(s, ..., delim = c("{", "}"), replace.NA = TRUE)
character
typically name/value pairs. See Examples.
characters
logical: if TRUE, NA
values are replaced by
the string "NA"
.
May also be a string. See Examples.
character
A light-weight replacement function.
# NOT RUN {
template <- "{1} meets {2}"
fill_in(template, "Peter", "Paul") ## "Peter meets Paul"
template <- "{one} meets {other}"
fill_in(template, one = "Peter", other = "Paul") ## "Peter meets Paul"
## handling missing values
fill_in("{name}: {score}", name = "Peter", score = NA)
## [1] "Peter: NA"
fill_in("{name}: {score}", name = "Peter", score = NA, replace.NA = ".")
## [1] "Peter: ."
# }
Run the code above in your browser using DataLab