[Rd] Change in grep behavior from 1.9.0 to R-patched

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jun 11 17:28:37 CEST 2004


This is actually PCRE.  Something is wrong with your build of R-patched
(1.9.1 alpha, I assume): I get 84 everywhere.  You are asking for a first
character l, then one or more characters of `word' then tmean.  In your
example this is the same as (in a suitable locale, including C)

length(grep("^l[A-Za-z0-9]+tmean", x, perl = TRUE, value = TRUE))
length(grep("^l[[:alnum:]_]+tmean", x, perl = TRUE, value = TRUE))

which each give 84.

One issue: PCRE is locale-dependent.  Did you use the same locale for 
each?  What happens if you force LANG=C?

(I've just checked an R-devel Solaris system.  This gave 13 on a build 
from Weds, and 84 when remade today.  The result with 13 seems truncated, 
as they are the first 13.  Might be coincidental, of course.)

On Fri, 11 Jun 2004, Roger D. Peng wrote:

> I've noticed a change in the way grep() behaves between the 1.9.0 
> release and a recent R-patched.  On 1.9.0 I get the following output:
> 
>  > x <- dget(file = url("http://www.biostat.jhsph.edu/~rpeng/names.R"))
>  > length(grep("^l\\w+tmean", x, perl = TRUE, value = TRUE))
> [1] 84
> 
> And on R-patched (2004-06-11) I get
> 
>  > x <- dget(file = url("http://www.biostat.jhsph.edu/~rpeng/names.R"))
>  > length(grep("^l\\w+tmean", x, perl = TRUE, value = TRUE))
> [1] 13
> 
> I can't come up with a simpler example which is why I've posted my 
> actual character vector on the web (please let me know if there are 
> problems downloading it).
> 
> I didn't find anything in the NEWs file that would indicate a change 

No change is intended and the underlying C code is unchanged.

> and another problem is that I'm not sure which behavior is correct. 
> My knowledge of regular expressions is limited.

-- 
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-devel mailing list