Skip to content
Prev 47339 / 63424 Next

In-string variable/symbol substitution: What formats/syntax is out there?

On Tue, Dec 17, 2013 at 4:44 PM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
Note that the gsubfn example above is the default only but by
specifying the pattern argument (first arg) it can be changed. e.g.

library(gsubfn)

pat <- "[$]([[:alpha:]][[:alnum:].]*)|[$][{]([^}]*)[}]"
gsubfn(pat,, "pi=$pi 2pi=${2*pi}")

pat2 <- "@([^@]*)@"
gsubfn(pat2,, "pi=@pi@ 2pi=@2*pi@")

pat3 <- "%([^%]*)%"
gsubfn(pat3,, "pi=%pi% 2pi=%2*pi%")

pat4 <- "{{(.*?)}}"
gsubfn(pat4,, "pi={{pi}} 2pi={{2*pi}}")