you need to escape it (twice):

>  sub(x='>|t|',pattern = '\\|t',replacement='zz')
[1] ">zz|"


On Fri, Apr 9, 2010 at 4:35 PM, David.Epstein
<David.Epstein@warwick.ac.uk>wrote:

>
> Here is my interaction with R:
> > sub(x='>|t|',pattern = '|t',replacement='zz')
> [1] "zz>|t|"
>
> So I say to myself "Clearly the | signs need to be escaped, so let's try
> this"
> > sub(x='>|t|',pattern = '\|t',replacement='zz')
> [1] "zz>|t|"
> Warning messages:
> 1: '\|' is an unrecognized escape in a character string
> 2: unrecognized escape removed from "\|t"
> How can \| be an unrecognized escape? This flatly contradicts
> help('regex'),
> or am I misunderstanding the help?
>
> The first pattern above works if one uses extended=F.
>
> What do R experts think?
>
> David
> --
> View this message in context:
> http://n4.nabble.com/perhaps-regular-expression-bug-with-sign-tp1819872p1819872.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

	[[alternative HTML version deleted]]

