[R] How do I get sub to insert a single backslash?

2006-01-05 Thread Michael Dewey
Something about the way R processes backslashes is defeating me.
Perhaps this is because I have only just started using R for text processing.

I would like to change occurrences of the ampersand  into ampersand 
preceded by a backslash.

  temp - R  D
  sub(, \, temp)
[1] R  D
  sub(, \\, temp)
[1] R  D
  sub(, \\\, temp)
[1] R  D
  sub(, , temp)
[1] R \\ D
 

So I can get zero, or two backslashes, but not one. I am sure this is 
really simple but I did not find the answer by doing, for example ?regexp 
or ?Quotes


Michael Dewey
http://www.aghmed.fsnet.co.uk

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How do I get sub to insert a single backslash?

2006-01-05 Thread Peter Dalgaard
Michael Dewey [EMAIL PROTECTED] writes:

 Something about the way R processes backslashes is defeating me.
 Perhaps this is because I have only just started using R for text processing.
 
 I would like to change occurrences of the ampersand  into ampersand 
 preceded by a backslash.
 
   temp - R  D
   sub(, \, temp)
 [1] R  D
   sub(, \\, temp)
 [1] R  D
   sub(, \\\, temp)
 [1] R  D
   sub(, , temp)
 [1] R \\ D
  
 
 So I can get zero, or two backslashes, but not one. I am sure this is 
 really simple but I did not find the answer by doing, for example ?regexp 
 or ?Quotes


None of those result strings  have two backslashes!


Hint:

 nchar(R \\ D)
[1] 6

and ?Quotes tellse the entire story.

-- 
   O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html