| gsubfn-package {gsubfn} | R Documentation |
Generalized "'gsub'" and associated function.
"'gsubfn'" is like "'gsub'" except
instead of using a replacement string it passes
the matches and backreferences to a function
which transforms them and then replaces the matches
with that. Some applications include
perl-style string interpolation, splitting a string
based on matches rather than delimiters (using
the function "'strapply'") and other
string transformation applications.
Index:
gsubfn Pattern Matching and Replacement strapply Apply a function over a string or strings.
# replace each number with that number plus 1
gsubfn("[[:digit:]]+", function(x) as.numeric(x)+1, "(10 20)(100 30)")
# perl-style string interpolation
gsubfn(,, "pi = $pi\n")
# split out numbers
strapply("12abc34 55", "[0-9]+")