[R] [R-pkgs] New verion 0.3-7 of gsubfn package
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Oct 20 15:45:36 CEST 2008
Version 0.3-7 of the gsubfn package is available on CRAN.
Changes to the package are:
- all known bugs have been fixed.
- in gsubfn and strapply the replacement object can be a
list (or a function, formula, character string or proto
object, as before). In the case of a list, regexp matches
are looked up in the list names and the corresponding list
component used.
# Example 1 - at string end replace M with e6 & G with e9
gsubfn(".$", list(M = "e6", G = "e9"), c("19G", "32.5M"))
- the backref= argument in gsubfn now defaults to the
negative of its prior default. Thus by default if there
are back references only they and not the entire match is
passed to the user function. (Although the changed
default introduces an incompatibility with prior versions
this incompatability is small because it only affects
situations where back references are present in the
regular expression _and_ backref= was not used. Since the
previous default for backref= was not useful in that case
there would be very few, if any, such instances.) On the
other hand, it does mean that the backref= argument can be
omitted most cases now.
For more info, see home page and brief description below.
http://gsubfn.googlecode.com
The gsubfn package - summary
============================
A seemingly small enhancement to R's gsub function, allowing
the replacement string to be a function, formula, list or
proto object gives surprising additional power allowing
parsing of strings by content rather than delimiters. e.g.
extract numbers:
# Example 2. Replace each number with its increment
gsubfn("[0-9]+", ~ as.numeric(x) + 1, "90 and 17")
# Example 3. extract numbers
strapply("Over 90 stones in 17 places", "[0-9]+")
The optional function passed to gsubfn and strapply may be
specified using usual R function notation or by a formula
whose left hand side represents the arguments (defaulting to
variables appearing in right hand side) and whose right hand
side represents the body. In order to extend this
functionality beyond gsubfn and strapply to the rest of R
any R function may be prefaced with fn$ like this:
# Example 4. Integrate x^2
fn$integrate(~ x^2, 0, 1)
It also supports quasi-perl style string interpolation:
# Example 5. Quasi-perl style string interpolation
fn$cat("pi = $pi and e = `exp(1)`\n")
match.funfn is an alternative to match.fun which allows
developers to add this functionality to their own functions
by simply replacing match.fun with match.funfn -- a one line
change. In that case even the fn$ prefix is not needed.
_______________________________________________
R-packages mailing list
R-packages at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
More information about the R-help
mailing list