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

From: Spencer Graves <>
Date: Tue 28 Jun 2005 - 02:41:19 EST

          Thanks, Dirk, Gabor, Eric:

          You all provided appropriate solutions for the stated problem. Sadly, I oversimplified the problem I was trying to solve: I copy a character string giving a DOS path from MS Windows Explorer into an R script file, and I get something like the following:


          I want to be able to use this in R with its non-R meaning, e.g., in readLine, count.fields, read.table, etc., after appending a file name. Your three solutions all work for my oversimplified toy example but are inadequate for the problem I really want to solve.

	  spencer graves

Gabor Grothendieck wrote:

> On 6/27/05, Dirk Eddelbuettel <> 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")
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA <>
Tel:  408-938-4420
Fax: 408-280-7915

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Tue Jun 28 02:56:28 2005

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