From ggrothendieck at gmail.com  Mon May  7 16:37:30 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Mon, 7 May 2007 10:37:30 -0400
Subject: [Rd] grep with fixed=TRUE and ignore.case=TRUE
In-Reply-To: <20070507142012.GF31253@cs.cas.cz>
References: <20070428114959.GA25723@cs.cas.cz>
	<46337DE1.5030607@statistik.uni-dortmund.de>
	<20070429135347.GA4690@cs.cas.cz> <20070507142012.GF31253@cs.cas.cz>
Message-ID: <971536df0705070737g6f8ac4b5k9a4c15529e4672ef@mail.gmail.com>

Seems like a good idea to me.

Here is a workaround that works in any event which combines (?i), \Q and \E .
to get the same effect.  (?i) gives case insensitive matches and \Q and \E
quote and endquote the intervening text disabling special characters:

x <- c("D.G cat", "d.g cat", "dog cat")
z <- "d.g"
rx <- paste("(?i)\\Q", z, "\\E", sep = "")
grep(rx, x, perl = TRUE)  # 1 2


On 5/7/07, Petr Savicky <savicky at cs.cas.cz> wrote:
> Dear R developers,
>
> I suggest to modify the behaviour of "grep" function with fixed=TRUE option.
>
> Currently, fixed=TRUE implies ignore.case=FALSE (overrides ignore.case=TRUE,
> if set by the user).
>
> I suggest to keep ignore.case as set by the user even if fixed=TRUE. Since
> the default of ignore.case is FALSE, this would not change the behaviour
> of grep, if the user does not set ignore.case explicitly.
>
> In my opinion, fixed=TRUE is most useful for suppressing meta-character
> expansion. On the other hand, for a simple word search, ignoring
> case is sometimes useful.
>
> If for some reason, it is better to keep the current behavior of grep, then I
> suggest to extend the documentation as follows:
>
> ORIGINAL:
>   fixed: logical.  If 'TRUE', 'pattern' is a string to be matched as
>          is.  Overrides all conflicting arguments.
>
> SUGGESTED:
>   fixed: logical.  If 'TRUE', 'pattern' is a string to be matched as
>          is.  Overrides all conflicting arguments including ignore.case.
>
> All the best, Petr Savicky.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] grep with fixed=TRUE and ignore.case=TRUE
Gabor Grothendieck