Learn R Programming

gsubfn (version 0.1-3)

gsubfn-package: gsubfn

Description

Generalized "'gsub'" and associated function.

Arguments

Details

"'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. The following are sources of information on "gsubfn": ll{ News file.show(system.file("NEWS", package = "gsubfn")) Wish List file.show(system.file("WISHLIST", package = "gsubfn")) This File package?gsubfn Help files ?gsubfn, ?strapply, ?cati } Index: gsubfn Pattern Matching and Replacement cati cat but with gsubfn-style interpolation. strapply Apply a function over a string or strings.

Examples

Run this code
# replace each number with that number plus 1
gsubfn("[[:digit:]]+", function(x) as.numeric(x)+1, "(10 20)(100 30)") 

# perl-style string interpolation
cati("pi = $pi, e = `exp(1)`\n")

# split out numbers
strapply("12abc34 55", "[0-9]+")

Run the code above in your browser using DataLab