gsubfn is an R package used for string matching, substitution and parsing. A
seemingly small generalization of gsub, namely allow the replacement string to
be a replacement function, list,
formula or proto object, can result in significantly
increased power and applicability. The resulting function, gsubfn is the
namesake of this package.
In the case of a replacement formula the formula is interpreted
as a function with the body of the function represented by the right hand side of
the formula. In the case of a replacement proto
object the object space is used to store persistant data to be communicated
from one function invocation to the next as well as to store the replacement
function/method itself.
Built on top of gsubfn is strapply which is similar
to gsubfn except that it returns the output of the function rather than
substituting it back into the source string.
A fast version of strapply specialized to the function c
is provided.
The ability to have formula arguments that represent functions can be used not
only in the functions of the gsubfn package but can also be used with any R
function that itself passes functions without modifying its source.
Such functions might include apply, lapply, mapply, sapply, tapply, by,
integrate, optim, outer and other functions in the core of R and in addon
packages. Just
preface any R function with fn\$
and
subject to certain rules which are intended to distinguish which formulas are
intended to be functions and which are not, the formula arguments will be
translated to functions, e.g. fn$integrate(~ x^2, 0, 1)
fn\$
also performs quasi-perl style string interpolation on any
character arguments beginning with \1
.
match.funfn
, is provided to allow developers to readily build this
functionality into their own functions so that even the fn\$
prefix need not be used.
The home page plus the following are sources of information on "gsubfn"
:
Home Page (see URL: line) |
RShowDoc("DESCRIPTION", package = "gsubfn") |
News |
RShowDoc("NEWS", package = "gsubfn") |
Wish List |
RShowDoc("WISHLIST", package = "gsubfn") |
Thanks file |
RShowDoc("THANKS", package = "gsubfn") |
License |
RShowDoc("COPYING", package = "gsubfn") |
Citation |
citation(package = "gsubfn") |
Demo |
demo("gsubfn-chron") |
Demo |
demo("gsubfn-cut") |
Demo |
demo("gsubfn-gries") |
Demo |
demo("gsubfn-si") |
Unit tests |
demo("gsubfn-unitTests") |
This File |
package?gsubfn |
Help files |
?gsubfn, ?strapply, ?cat0 |
More Help files |
?as.function.formula, ?match.funfn, ?fn |
Home page |
http://code.google.com/p/gsubfn/ |
Vignette |
vignette("gsubfn") |