[R] regex -> negate a word

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jan 19 11:32:40 CET 2009


On Mon, 19 Jan 2009, Rolf Turner wrote:

>
> On 19/01/2009, at 10:44 AM, Gabor Grothendieck wrote:
>
>> Well, that's why it was only provided when you insisted.  This is
>> not what regexp's are good at.
>> 
>> On Sun, Jan 18, 2009 at 4:35 PM, Rau, Roland <Rau at demogr.mpg.de> wrote:
>>> Thanks! (I have to admit, though, that I expected something simple)
>
> It may not be what regexp's are good at, but the grep command in unix/linux
> does what is required *very* simply via the ``-v'' flag.  I conjecture that
> it would not be difficult to add an argument with similar impact to the
> grep() function in R.

Indeed.  I have often wondered why grep() returned indices, when a 
logical vector would seem more natural in R (and !grep(...) would have 
been all that was needed).

Looking at the code I see it does in fact compute a logical vector, 
just not return it.  So adding 'invert' (the long-form of -v is 
--invert) is a job of a very few lines and I have done so for 2.9.0.

-- 
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