[R] How to convert "c:\a\b" to "c:/a/b"?

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jun 27 07:23:02 CEST 2005


On 6/27/05, Dirk Eddelbuettel <edd at debian.org> wrote:
> 
> On 26 June 2005 at 20:30, Spencer Graves wrote:
> |         How can one convert back slashes to forward slashes, e.g, changing
> | "c:\a\b" to "c:/a/b"?  I tried the following:
> |
> |  > gsub("\\\\", "/", "c:\a\b")
> | [1] "c:\a\b"
> 
> This does work, provided you remember that single backslashed "don't exist"
> as e.g. \a is a character in itself. So use doubles are you should be fine:
> 
> > gsub("\\\\", "/", "c:\\a\\b")
> [1] "c:/a/b"
> 

Also, if one finds four backslashes confusing one can avoid the use 
of four via any of these:

gsub("[\\]", "/", "c:\\a\\b")
gsub("\\", "/", "c:\\a\\b", fixed = TRUE)
chartr("\\", "/", "c:\\a\\b")




More information about the R-help mailing list