[R-pkgs] New verion 0.3-7 of gsubfn package

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 20 Oct 2008 09:45:36 -0400

Version 0.3-7 of the gsubfn package is available on CRAN. Changes to the package are:

  # Example 1 - at string end replace M with e6 & G with e9   gsubfn(".$", list(M = "e6", G = "e9"), c("19G", "32.5M"))

For more info, see home page and brief description below.


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
https://stat.ethz.ch/mailman/listinfo/r-packages Received on Tue 21 Oct 2008 - 00:47:31 EST

This archive was generated by hypermail 2.2.0 : Tue 21 Oct 2008 - 01:00:01 EST