Re: [R] Replacing backslashes with slashes

From: Elizabeth Lawson <>
Date: Thu 05 Jan 2006 - 03:00:38 EST


> name<-"C:\\myfile.txt"
> name

[1] "C:\\myfile.txt"
> gsub("([\\])","\\/",name)

[1] "C:/myfile.txt"

yvonnick noel <> wrote:   Hello,

I've seen this question asked in the archives but no clear reply or solution provided. So, just to be sure it is not possible in R: Can I replace backslashes with slashes in a string ?

I am writing a GUI for R with the Rpad library. I have a "browse" button for data loading and Windows return a path string with backslashes. I need to convert them into slashes to use the string with read.table.

I would have expected something like:

gsub("\\","\/","c:\My Documents\data.dat")

to work but it does not (incorrect regular expression).

Note that I have no control on the string which is returned from the system (no such problem under Linux BTW).

Any idea ?

Yvonnick NOEL
U. of Rennes 2
FRANCE mailing list PLEASE do read the posting guide!                            

 Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide! Received on Thu Jan 05 03:41:51 2006

This archive was generated by hypermail 2.1.8 : Thu 05 Jan 2006 - 05:29:26 EST