Utilities for Strings and Function Arguments

The gsubfn function is like gsub but can take a replacement function or certain other objects instead of the replacement string. Matches and back references are input to the replacement function and replaced by the function output. gsubfn can be used to split strings based on content rather than delimiters and for quasi-perl-style string interpolation. The package also has facilities for translating formulas to functions and allowing such formulas in function calls instead of functions. This can be used with R functions such as apply, sapply, lapply, optim, integrate, xyplot, Filter and any other function that expects another function as an input argument or functions like cat or sql calls that may involve strings where substitution is desirable. There is also a facility for returning multiple objects from functions and a version of transform that allows the RHS to refer to LHS used in the same transform.


News

Changes in 0.7-0

o transform2 added

Changes in 0.6-7

o list[...] <- added for enabling multiple return values

Changes in 0.6-6

o bug fix. strapplyc failed with "R" engine.

o new read.pattern function

o vignettes have been moved to vignette directory to satisfy R 3.1,0

Changes in 0.6-5

o the Vignettes menu has been removed removing any dependence on Zelig.

Changes in 0.6-4

o in interactive Windows sessions under Rgui a Vignettes menu is created
  (or added to if present) provided the Zelig package is available

o a scoping bug in fn$ was fixed

o gsubfn was attempting to access the tcltk package even if the
  gsubfn.engine = "R" option was set. Fixed.

o changes to accommodate R-2.16: (i) a non-ascii character in the
  gsubfn-si demo was removed (ii) rep on a pairlist is no longer 
  supported by R but used by fn$ so a workaround was implemented

o modified demos: (i) gsubfn-chron demo simplified based on latest
  read.zoo, (ii) modified gsubfn-gries to use lipsum.txt (which was
  added), (iii) mu in gsubfn-si changed to u so its all ASCII.

Changes in 0.6-3

o strapplyc could not find tcltk.  Fixed.

o paste0 has been implemented in the base of R as of R 2.15.0 so it has 
  been removed from this version of sqldf.

Changes in 0.6-2

o package is now byte compiled hence depends on 2.14.0 or higher

o if tcltk can be loaded it is loaded at startup.  If not, the gsubfn.engine
  option is set to "R", a message is given and subsequent calls will use 
  slower R code instead of tcltk.  Previously this check was done at run
  time in the individual functions.

o strapplyc now calls strapply if gsubfn.engine = "R"

o now uses withVisible instead of internal function eval.with.vis.  This
  internal change was made to satisfy R 2.15.0 and should not affect users.

o added more unit tests

Changes in 0.6

o strapplyc added, a fast tcl-only version of strapply specialized to FUN=c.

o bug fix.  perl was ignored when engine = "tcl".

o unit test suite added.  demo("gsubfn-unitTests") will run it.

o added NAMESPACE

Changes in 0.5-6

o bug fix. backref argument was being interpreted incorrectly in "R" engine.

Changes in 0.5-5

o bug fix - engine option was not being interpreted correctly.  

Changes in 0.5-4

o strapply with engine = "tcl" (the default) now runs much faster on long 
  strings

Changes in 0.5-3

o new argument, empty, on strapply

o gsubfn now has an engine argument.  This was already the case
  with strapply.

o new global option "gsubfn.engine" whose value can be "tcl" or "R". It is
  used as the default value for the gsubfn and strappy engine argument.  If
  the option is not set then gsubfn and strapply default to the "tcl" 
  regular expression engine if the current R installation has tcltk 
  capability and "R" otherwise.

o gsubfn pattern is no longer parenthesized internally if (1) engine = "tcl"
  or if (2) engine = "R" and backref > 0.  See the example of replacing 
  double characters in ?gsubfn .

o if the function in gsubfn or strapply has an `&` argument then backref
  will be taken to be negative and the entire match passed through that arg.

o in as.function.formula if any of ..1 through ..9 are found as free
  variables then ... is used as a trailng argument instead. If `&` is a
  free variable then it is placed at the beginning of the argument list.

Changes in 0.5-2

o bug fixes

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.

Changes in 0.3-9

o removed some dead code.  Thanks to Wacek Kusnierczyk.

Changes in 0.3-8

o minor improvements in gsubfn-package.Rd

o fixed bug in match.funfn

o heuristic to detect the number of back references (used when backref
  is not specified) now uses -k where k is the number of non-escaped
  left parens (whereas previously it used -k where k was the number of 
  left parens whether escaped or not).

Changes in 0.3-7

o R CMD CHECK fixes

o if replacement object is a list and match not found in that list then
  no replacement is done

Changes in 0.3-6

o bug fixes: fn$force("$x") failed if variable name was x as shown here

o bug fixes: f <- function() { aaa <- "X"; fn$cat("abc$aaa def\n") }; f()
  failed.

o internals: eval.with.vis() replaced in $.fn.  Now using withVisible().
  This change requires R 2.5 or later.

o the replacement object in gsubfn can be a list as well

o the replacement object in strapply can be a character string or list
  as well

o if backref= is omitted on gsubfn or strapply it passes the backreferences
  if any (but not the entire match) or if there are no back references
  it passes the entire match.  Thus the default has changed in the case
  that (1) there are one or more backreferences in the regular expression 
  and (2) backref was not specified.  This should eliminate the need to 
  specify backref in most circumstances.  Note that if there are no 
  backreferences in your regular expression or if backref= had been
  specified there is no change thus in most cases there will be no change.

Changes in 0.3-5

o fixed bug in demo index

o eliminated dependence on methods package (previously only
  dependence was use of 'is')

Changes in 0.3-4

o fixed typo

Changes in 0.3-3

o changed quantreg example to reflect change in engel data set

Changes in 0.3-2

o revised gsubfn-packages.Rd

o fn$ now performs quasi-perl style interpolation 

o cati, cati0 removed since fn$cat and fn$cat0 can be used.

o rules for which formulas are translated and which character 
  strings are interpolated have been changed and simplified:
  1. formulas specified with ~~ (double ~) are translated to functions
  2. character strings beginning with \1 are translated to functions
  3. if the above rules result in no translation/interpolation
     then all formulas are translated if there are any formulas
     or, if not, then all character strings are interpolated
     In most cases rule #3 is used.

o fn$f now returns invisibly if f does (thanks to Duncan Murdoch
  for eval.with.vis)

Changes in 0.3-1

o fixed initialization bug in strapply

o added proto examples to ?gsubfn and ?strapply

Changes in 0.3-0

o gsubfn and strapply now can take proto arguments in addition
  to character strings, functions and formulas

o vignette added

o home page abbreviated since most info already in vignette

Changes in 0.2-3

o increased string lengths accepted by gsubfn by eliminating
  use of the R parse() command. [Thanks to Stefan Th. Gries
  for reporting problem.]

o fixed bug in one of the examples in example(gsubfn)

o strapply fixes

Changes in 0.2-2

o added combine= argument to strapply

o fixed bug associated with using double quotes in gsub (which
  also could affect strapply and cati).  [Thanks to Stefan Th.
  Gries for reporting problem.]

Changes in 0.2-1

o added "note difference" example in strapply

o letters, LETTERS and pi excluded from args so 
  x ~ sin(x*pi/180) can be shortened to ~ sin(x*pi/180)
  and 
  x ~ LETTERS[x] can be reduced to ~ LETTERS[x]
  (previously it would have added pi and LETTERS to arg
  lists in these two examples)

o improved as.function.formula.Rd

o fixes to eliminate R CMD CHECK warnings under R 2.5.0

o bug fix in $.fn.  If args and match.call order was different
  it could fail previously.

o new demos: gsubfn-gries.R, gsubfn-chron.R, gsubfn-si.R

o THANKS file

Changes in 0.2-0

o match.funfn

o as.function.formula improvements

o $.fn

o added numerous examples of $.fn to home page

Changes in 0.1-5

o reference to cat0 missing from gsubfn-package.Rd

o added digit separation example to strapply.Rd

o added config file example to strapply.Rd

o in strapply simplify= can be a function

o replacement= in gsubfn and strapply can be a formula

o new internal function as.function.formula

o new home page and svn repository (URL in DESCRIPTION file)

Changes in 0.1-4

o added cati, cati0, cat0 and paste0

o added USE.NAMES argument to gsubfn

o added gsubfn-cut demo

o added repx example to gsubfn.Rd

o added SI scale example to gsubfn.Rd

o perl=, etc. args were not being passed to gsub

o added moving window example to strapply.Rd

Changes in 0.1-3

o enhanced gsubfn backref= argument

o fixed bug in strapply

Changes in 0.1-2

o cati added

o updated DESCRIPTION and gsubfn-package.Rd

Changes in 0.1-1

o strapply added

o gsubfn-package.Rd added

Changes in 0.1-0

o initial release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("gsubfn")

0.7 by G. Grothendieck, a year ago


https://github.com/ggrothendieck/gsubfn


Report a bug at https://github.com/ggrothendieck/gsubfn/issues


Browse source code at https://github.com/cran/gsubfn


Authors: G. Grothendieck


Documentation:   PDF Manual  


Task views: Natural Language Processing


GPL (>= 2) license


Depends on proto

Suggests boot, chron, grid, lattice, quantreg, svUnit, tcltk, zoo


Imported by ITGM, MplusAutomation, SpecHelpers, datamart, iemisc, priceR, rSQM, smartR, smbinning, vmsbase.

Depended on by fscaret, sqldf.

Suggested by ChemoSpec, lulcc, rtf.


See at CRAN