The gsubfn package allows you to preface any function with fn$ in which case character arguments will support perl-style string interpolation using backticks or $ sign (and formula notation can be used for function arguments).
library(gsubfn)
name <- "Eric"
age <- 42
fn$plot(0, main = "Hello, `name`. You are `age`.")
The part within backticks can be an R expression:
fn$identity("Hello, `name`. You are `age+1`.")
## [1] "Hello, Eric. You are 43."
It also supports $ notation if the end of the variable name can be inferred from the string. That is not the case in the above since dot is valid in a variable name but this would work:
fn$c("Hello $name")
## [1] "Hello Eric"
One can also use gsubfn from the same package. This looks for a string surrounded by brace brackets and then substitutes the variable name in it for its contents.
gsubfn("{(.*?)}", get, "Hello, {name}. You are {age}.")
## [1] "Hello, Eric. You are 42."
or a list can be provided as the second argument
L <- list(name = "Eric", age = 42)
gsubfn("{(.*?)}", L, "Hello, {name}. You are {age}.")
## [1] "Hello, Eric. You are 42."
This would also work using the same list. It avoids the use of {...} and would work as long as name and age do not appear elsewhere in the string. It looks up words, i.e. substrings made up of word characters, in the list.
gsubfn("\\w+", L, "Hello, name. You are age.")
## [1] "Hello, Eric. You are 42."