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

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon 27 Jun 2005 - 15:23:02 EST

On 6/27/05, Dirk Eddelbuettel <edd@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")

______________________________________________
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 Received on Mon Jun 27 15:28:13 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:03 EST