Skip to content

Commit

Permalink
version 0.5-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrothendieck authored and gaborcsardi committed Mar 15, 2010
1 parent 954ffba commit 0739942
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 103 deletions.
13 changes: 7 additions & 6 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: gsubfn
Version: 0.5-0
Date: 2009-07-01
Version: 0.5-1
Date: 2010-03-15
Title: Utilities for strings and function arguments.
Author: G. Grothendieck
Maintainer: G. Grothendieck <ggrothendieck@gmail.com>
Expand All @@ -17,10 +17,11 @@ Description: gsubfn is like gsub but can take a replacement function or
that expects another function as an input argument or functions
like cat or sql calls that may involve strings where
substitution is desirable.
Depends: R (>= 2.5.0), proto, tcltk
Suggests: boot, chron, doBy, grid, lattice, quantreg, reshape, zoo
Depends: R (>= 2.5.0), proto
Suggests: boot, chron, doBy, grid, lattice, quantreg, reshape, tcltk,
zoo
License: GPL (>= 2)
URL: http://gsubfn.googlecode.com
Packaged: 2009-07-02 03:51:32 UTC; Louis
Packaged: 2010-03-16 17:07:11 UTC; Louis
Repository: CRAN
Date/Publication: 2009-07-02 06:52:07
Date/Publication: 2010-03-16 17:23:48
8 changes: 7 additions & 1 deletion R/gsubfn.R
Expand Up @@ -44,6 +44,7 @@ gsubfn <- function(pattern, replacement, x, backref, USE.NAMES = FALSE,
}
# if (inherits(replacement, "formula")) replacement <- as.function(replacement)
if (missing(pattern)) pattern <- "[$]([[:alpha:]][[:alnum:].]*)|`([^`]+)`"
pattern <- as.character(pattern)
# i is 1 if the entire match is passed and 2 otherwise.
# j is 1 plus the number of backreferences
if (missing(backref) || is.null(backref)) {
Expand Down Expand Up @@ -188,13 +189,18 @@ function (X, pattern, FUN = function(x, ...) x, ...,

strapply <-
function (X, pattern, FUN = function(x, ...) x, backref = NULL, ...,
ignore.case = FALSE, perl = FALSE, engine = c("tcl", "R"),
ignore.case = FALSE, perl = FALSE,
engine = if (isTRUE(capabilities()[["tcltk"]])) "tcl" else "R",
simplify = FALSE, USE.NAMES = FALSE, combine = c) {
engine <- match.arg(engine)
combine <- match.funfn(combine)
stopifnot(!missing(pattern))
pattern <- as.character(pattern)
if (engine == "R" || is.proto(FUN) || perl) return(ostrapply(X = X,
pattern = pattern, FUN = FUN, backref = backref,
..., perl = perl, simplify = simplify, USE.NAMES = USE.NAMES,
combine = combine))
stopifnot(require(tcltk))
if (is.proto(FUN)) {
# TODO
} else if (is.character(FUN)) {
Expand Down
10 changes: 9 additions & 1 deletion inst/NEWS
@@ -1,4 +1,12 @@
Changes in 0.4-0
Changes in 0.5-1

o fixes to pass R CMD CHECK

o package no longer depends on tcltk but it is still suggested. If R
installation does not have tcltk capability then strapply falls back
to R engine.

Changes in 0.5-0

o faster strapply based on tcl interface. engine argument can choose
between it and older version of strapply.
Expand Down
Binary file modified inst/doc/Rplots.pdf
Binary file not shown.
75 changes: 0 additions & 75 deletions inst/doc/a.a

This file was deleted.

Binary file removed inst/doc/gsubfn-16.10.2008-14.02.36.23.bck.pdf
Binary file not shown.
6 changes: 1 addition & 5 deletions inst/doc/gsubfn.Rnw
Expand Up @@ -628,17 +628,13 @@ calculates a weighted mean of the first column using weights in
the second column all grouped by columns \code{A} and \code{B}.
The \code{aggregate} example aggregates over indexes to circumvent
the restriction of a single input to the aggregation function.
Since both \code{i} and \code{X} are free variables but we only
Both \code{i} and \code{X} are free variables but we only
want \code{i} to be an argument so we must specify it explicitly.
In the \code{by} example there is only one free variable \code{x}
so we can rely on the default for argument processing.
Also note the use of \code{simplify=rbind} in the \code{by} case:
<<gsubfn-fn-aggregate2>>=
set.seed(1)
X <- data.frame(X = rnorm(24), W = runif(24), A = gl(2, 1, 24), B = gl(2, 2, 24))
fn$aggregate(1:nrow(X), X[3:4], i ~ weighted.mean(X[i,1], X[i,2]))
fn$by(X, X[3:4], ~ data.frame(wmean = weighted.mean(x[1], x[2]), x[1, 3:4]), simplify = rbind)
@
A number of mathematical functions take functions as arguments. Here we
Expand Down
Binary file modified inst/doc/gsubfn.pdf
Binary file not shown.
15 changes: 7 additions & 8 deletions man/gsubfn.Rd
Expand Up @@ -5,17 +5,17 @@

\title{ Pattern Matching and Replacement }
\description{
Like \code{\link[base]{gsub}} except instead of a replacement string one
Like \code{gsub} except instead of a replacement string one
uses a function which accepts the matched text as input and emits
replacement text for it.
}
\usage{
gsubfn(pattern, replacement, x, backref, USE.NAMES = FALSE, env = parent.frame(), ...)
}
\arguments{
\item{pattern}{ Same as \code{pattern} in \code{\link[base]{gsub}} }
\item{pattern}{ Same as \code{pattern} in \code{gsub} }
\item{replacement}{ A character string, function, list, formula or proto object. See Details. }
\item{x}{ Same as \code{x} in \code{\link[base]{gsub}} }
\item{x}{ Same as \code{x} in \code{gsub} }
\item{backref}{ Number of backreferences to be passed to function.
If zero or positive the match is passed as the first argument to the replacement
function followed by the indicated number of backreferences as subsequent
Expand All @@ -25,10 +25,10 @@ If omitted it will be determined automatically, i.e. it will be 0 if there
are no backreferences and otherwise it will equal negative the number of
back refenrences. It determines this by counting the number of non-escaped
left parentheses in the pattern.}
\item{USE.NAMES}{ See \code{USE.NAMES} in \code{\link[base]{sapply}}. }
\item{USE.NAMES}{ See \code{USE.NAMES} in \code{sapply}. }
\item{env}{ Environment in which to evaluate the replacement function.
Normally this is left at its default value.}
\item{\dots}{ Other \code{\link[base]{gsub}} arguments. }
\item{\dots}{ Other \code{gsub} arguments. }
}
\details{
If \code{replacement} is a string then it acts like \code{gsub}.
Expand Down Expand Up @@ -79,10 +79,9 @@ Normally this is left at its default value.}
\code{sep} value is \code{""}.
}
\value{
As in \code{\link[base]{gsub}}.
As in \code{gsub}.
}
\seealso{ \code{\link[base]{gsub}}, \code{\link[base]{strapply}}, \code{\link[base]{cat}},
\code{\link[base]{paste}} }
\seealso{ \code{\link{strapply}} }

\examples{

Expand Down
13 changes: 6 additions & 7 deletions man/strapply.Rd
Expand Up @@ -10,7 +10,8 @@ Similar to \code{"'gsubfn'"} except instead of performing substitutions
it returns the output of \code{"'FUN'"}.}
\usage{
strapply(X, pattern, FUN = function(x, ...) x, backref = NULL, ...,
ignore.case = FALSE, perl = FALSE, engine = c("tcl", "R"),
ignore.case = FALSE, perl = FALSE,
engine = if (isTRUE(capabilities()[["tcltk"]])) "tcl" else "R",
simplify = FALSE, USE.NAMES = FALSE, combine = c)
}
\arguments{
Expand All @@ -26,8 +27,8 @@ strapply(X, pattern, FUN = function(x, ...) x, backref = NULL, ...,
argument.}
\item{perl}{If \code{TRUE} then \code{engine="R"} is used with
perl regular expressions.}
\item{engine}{Specifies which engine to use. \code{engine="tcl"},
the default
\item{engine}{Specifies which engine to use. If the R installation
has \code{tcltk} capability then the \code{tcl} engine is used
unless \code{FUN} is a proto object in which case the
\code{"R"} engine is used (regardless of the setting of this
argument).}
Expand Down Expand Up @@ -70,12 +71,10 @@ sentence never occurs.
\value{
A list of character strings.
}
\seealso{ See \code{\link{gsubfn}} and
\code{\link[base]{sapply}}.
\seealso{ See \code{\link{gsubfn}}.
For regular expression syntax used in tcl see
\url{http://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm}
and for regular expression syntax used in R see
\code{\link[base]{regex}}.
and for regular expression syntax used in R see the help page for \code{regex}.
}
\examples{

Expand Down

0 comments on commit 0739942

Please sign in to comment.