# adds 1 to each number in third arg
gsubfn("[[:digit:]]+", function(x) as.numeric(x)+1, "(10 20)(100 30)")
# replaces pairs m:n with their sum
f <- function(x,y) as.numeric(x)+as.numeric(y)
gsubfn("([0-9]+):([0-9]+)", f, "abc 10:20 def 30:40 50", backref = -2)
gsubfn( , , "pi = $pi, 2pi = `2*pi`")
# Extracts numbers from string and places them into numeric vector v.
# Also see ?strapply
v <- c(); f <- function(x) v <<- append(v,as.numeric(x))
junk <- gsubfn("[0-9]+", f, "12;34:56,89,,12")
v
# makes all letters except first in word lower case
gsubfn("\\B.", tolower, "I LIKE A BANANA SPLIT")
Run the code above in your browser using DataLab