On 11/05/2007 7:07 AM, Vittorio wrote:
> Given the string
> 
>> mystr <- "(Preconsuntivo  del  giorno gas 10 maggio 
> 2007)Tj"
> 
> I'm trying to detect and eliminate the string ")Tj" at the 
> very end of mystr by means of 
> gsub(rx2,"",mystr) BUT preparing the 
> matching regexp string a warning pops up
> 
>> rx2 <- "\)Tj$"
> Warning 
> messages:
> 1: '\)' is an unrecognized escape in a character string 
> 2: 
> unrecognized escape removed from "\)Tj$" 
> 
> and
> 
>> rx2
> [1] ")Tj$"
> 
> I 
> tried also rx2 <- "(\))Tj$" but the result is the same.
> 
> What am I 
> missing?

You want the escaping to occur in gsub, not in R.  So you want to escape 
the escape:

rx3 <- "\\)Tj$"
gsub(rx3, "", mystr)

Duncan Murdoch

______________________________________________
[email protected] 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