You need double backslashes:

grep('\\.f', cvec, value = TRUE)

On Mon, Sep 14, 2009 at 4:25 PM, Prof. John C Nash <nas...@uottawa.ca>wrote:

> If I run
>
>
> cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f")
> print(cvec)
> indx<-grep('\.f',cvec,perl=TRUE)
> fset<-cvec[indx]
> print(fset)
>
> I get
>
> > cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f")
> > print(cvec)
> [1] "test.f"  "test.sf" "try.g"   "try.res" "try.f"
> > indx<-grep("\.f",cvec,perl=TRUE)
> Warning messages:
> 1: '\.' is an unrecognized escape in a character string
> 2: unrecognized escape removed from "\.f"
> > fset<-cvec[indx]
> > print(fset)
> [1] "test.f"  "test.sf" "try.f"
> >
>
> This ignores the . for which I want to test.
>
> In perl, the function
>
> #!/usr/bin/perl
> use strict;
> my @cvec=("test.f", "test.sf", "try.g","try.res", "try.f");
> foreach my $elem (@cvec) {
>   print "$elem : ";
>   if ( $elem =~ '\.f' ) {
>       print "matches \n";
>   } else {
>       print "does not match \n";
>   }
> }
>
>
> gives
>
> $ perl perlmatch.pl
> test.f : matches
> test.sf : does not match
> try.g : does not match
> try.res : does not match
> try.f : matches
> $
>
> which does what I want. It looks like a bug (or at least a nasty
> documentation failure) of "perl=TRUE".
>
> Anyone have suggestions of how to get appropriate filtering? I need this to
> automate optimization tests on large sets of test problems.
>
> Cheers, JN
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to