Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33d33b6
commit e4f7c88
Showing
20 changed files
with
369 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
46aaf69a91703493b666f212a04f2d8d *COPYING | ||
ec7a366d68a859e989142f1cd58e77b8 *COPYRIGHTS | ||
d87872761fefe42e37e48234ff0d9f16 *DESCRIPTION | ||
67ec5287bfca442488c725e68e24c155 *NAMESPACE | ||
a32c8ee5562489c5ea6bc1b4e122562a *R/fn.R | ||
8418e40994eb3a5d585d3ed7ebf62b58 *R/gsubfn.R | ||
cb4b5ed44d603df198ba67c497e60a93 *R/strapplyc.R | ||
4ee0d28766ebc2084c278e456996b633 *R/zzz.R | ||
fd368f5b6ac08f97596a66a7041109b4 *demo/00Index | ||
b02f0d688c7af2f2f012ebca2c3b2f66 *demo/gsubfn-chron.R | ||
dad9498d256e19cf92af106f3bed306b *demo/gsubfn-cut.R | ||
64e6b35d218602a5bcabf8df1861d205 *demo/gsubfn-gries.R | ||
97109cd369ca5a2fc15b2be55177aa61 *demo/gsubfn-lower.R | ||
93ceb63b260bf9f08398a1564a369cb2 *demo/gsubfn-si.R | ||
10af9aa7492b9c6beb4b939a3bc4da5d *demo/gsubfn-unitTests.R | ||
04f8a6fcfee3a5640e02cd9a324255ed *inst/ANNOUNCE | ||
c90a8201535f86b66f213f1ffce0f202 *inst/NEWS | ||
cd4675587428f7b6c4a52c1ff1303ee6 *inst/THANKS | ||
5e676f40f47703f3849c9c54c13d7fc4 *inst/WISHLIST | ||
cb61f6371fa5ba46bb6123a0c7994d59 *inst/doc/gsubfn-23.03.2012--8.55.13.11.bck.pdf | ||
a872d9493c1b5f73eabf439f297531fd *inst/doc/gsubfn.Rnw | ||
4e5c2749bdba3c88dad156c4d3e32fb5 *inst/doc/gsubfn.pdf | ||
c9e1d04a2d77929861d6c4944abff5c3 *inst/sample.txt | ||
e5c058b39406ad9f8245cce20411072f *inst/unitTests/runit.all.R | ||
1863bf11ffc8bf378f37688240f46e18 *man/as.function.formula.Rd | ||
7a9a388b5afa4a69bd43f326616eb7dd *man/fn.Rd | ||
10c46a80236ea6aff5c5d3b2c1062cad *man/gsubfn-package.Rd | ||
ce43e1646cb6ae897dd030ed30cf5a38 *man/gsubfn.Rd | ||
b53a82b0503f4e35bf5c3858fc4c76a1 *man/match.funfn.Rd | ||
20334eaf9d3b243dd7afd30a22e4f092 *man/strapply.Rd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Default NAMESPACE created by R | ||
# Remove the previous line if you edit this file | ||
|
||
# Export all names | ||
exportPattern(".") | ||
|
||
# Import all packages listed as Imports or Depends | ||
import( | ||
proto | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
library(tcltk) | ||
|
||
# x is name of a tcl variable holding list of character vectors | ||
tclList2R <- function(x, convert = as.character) { | ||
.Tcl <- tcltk::.Tcl | ||
len <- as.integer(.Tcl(sprintf("llength $%s", x))) | ||
f <- function(i) convert(.Tcl(sprintf("lindex $%s %d", x, i))) | ||
lapply(seq(0, len-1), f) | ||
} | ||
|
||
# high performance strapply with hard coded FUN=c. Guts in tcl. | ||
strapplyc <- function(X, pattern, backref, ignore.case = FALSE, simplify = FALSE, USE.NAMES = FALSE, engine = getOption("gsubfn.engine")) { | ||
if (identical(engine, "R")) return( | ||
strapply(X = X, pattern = pattern, FUN = "c", backref = backref, | ||
ignore.case = ignore.case, simplify = simplify, | ||
USE.NAMES = USE.NAMES, engine = engine) | ||
) | ||
.Tcl <- tcltk::.Tcl | ||
tcl <- tcltk::tcl | ||
tcl("set", "X", as.tclObj(X)) | ||
tcl("set", "pattern", pattern) | ||
tcl("set", "nocase", if (ignore.case) "-nocase" else "") | ||
if (missing(backref) || is.null(backref) || is.na(backref)) backref <- 999 | ||
tcl("set", "backref", backref) | ||
.Tcl("set about [regexp -about -- $pattern]") | ||
.Tcl("set about [lindex $about 0]") | ||
.Tcl("if { min($about, $backref) <= 0 } { set mn 0 } else { set mn 1 }") | ||
.Tcl("set mx [expr min($about, abs($backref))]") | ||
s <- paste('set result {} | ||
set k [expr $about + 1] | ||
if { $about == 0 || $about <= -$backref} { | ||
# this leg of the "if" returns everything from regexp so we | ||
# can avoid the extraction subloop of the "else" leg for speed | ||
foreach item $X { | ||
# {*} is new feature in tcl 8.5 to add level of substitution | ||
set cmd [list regexp -all -inline {*}$nocase -- $pattern $item] | ||
set res [{*}$cmd] | ||
lappend result $res | ||
} | ||
} else { | ||
foreach item $X { | ||
# {*} is new feature in tcl 8.5 that adds level of substitution | ||
set cmd [list regexp -all -inline {*}$nocase -- $pattern $item] | ||
set cmdout [{*}$cmd] | ||
set imin $mn | ||
set imax $mx | ||
set res {} | ||
while {$imax < [llength $cmdout]} { | ||
lappend res [lrange $cmdout $imin $imax] | ||
incr imin $k | ||
incr imax $k | ||
} | ||
lappend result [concat {*}$res] | ||
} | ||
}') | ||
.Tcl(s) | ||
out <- tclList2R("result") | ||
|
||
result <- sapply(out, identity, simplify = isTRUE(simplify), | ||
USE.NAMES = USE.NAMES) | ||
if (is.logical(simplify)) result else { | ||
do.call(match.funfn(simplify), result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
.onLoad <- function(libname, pkgname) { | ||
gsubfn.engine <- getOption("gsubfn.engine") | ||
# if gsubfn.engine was not set to "R" then check if tcltk can be used | ||
if ( ! identical(gsubfn.engine, "R") ) { | ||
tcltk.ok <- isTRUE(capabilities()[["tcltk"]]) && | ||
requireNamespace("tcltk", quietly = TRUE) | ||
if ( ! tcltk.ok ) { | ||
options(gsubfn.engine = "R") | ||
warning('Could not load tcltk. Will use slower R code instead.') | ||
} | ||
} | ||
|
||
} | ||
|
||
# .onUnload <- function(libpath) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
gsubfn-chron read in zoo data with chron datetimes. | ||
gsubfn-cut Use strapply to extract endpoints from cut labels. | ||
gsubfn-gries Stefan Gries' Linguistics code. | ||
gsubfn-lower Makes all letters in words lower case except first. | ||
gsubfn-si Replace SI scale letter with number. | ||
gsubfn-unitTests Run gsubfn unit test suite. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
# makes all letters except first in word lower case | ||
gsubfn("\\B.", tolower, "I LIKE A BANANA SPLIT", perl = TRUE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
library(gsubfn) | ||
library(svUnit) | ||
gsubfn.tests <- system.file("unitTests", "runit.all.R", package = "gsubfn") | ||
cat("Running:", gsubfn.tests, "\n") | ||
source(gsubfn.tests) | ||
clearLog() | ||
test.all() | ||
Log() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.