[R] recognizing "(" as a character

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Nov 15 19:22:46 CET 2003


On Sat, 15 Nov 2003, Thomas Lumley wrote:

> On Sat, 15 Nov 2003, Henrik Bengtsson wrote:
> 
> > You have to escape (="\\") such "special" characters, e.g.
> >
> >  strsplit("abc(d)(e)", split="\\(")
> >
> > or put them in brackets (matches sets of characters)
> >
> >  strsplit("abc(d)(e)", split="[(]")
> >
> > if you think that is more readable. Similar for gsub(), grep(),
> > regexpr() and friends.
> >
> 
> For all except (unfortunately) strsplit() there is now a fixed=TRUE
> argument to make this unnecessary.

As from 1.8.1 there will be a help page explaining what exactly a regexp
is.  You can use basic regexps here:

> strsplit("abc(d)(e)", split="(", extended=FALSE)
[[1]]
[1] "abc" "d)"  "e)" 

and those brought up on the original pre-POSIX Unix grep may be more
comfortable with that.

But it sounds like people would like a fixed=TRUE option too.


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list