[R] Replacing backslashes with slashes

yvonnick noel yvonnick.noel at uhb.fr
Wed Jan 4 17:34:11 CET 2006

> You need one of
> gsub("\\\\","/","c:\\My Documents\\data.dat")
> gsub("\\","/","c:\\My Documents\\data.dat", fixed = TRUE)
> chartr("\\", "/", "c:\\My Documents\\data.dat")

The string I get is an ASCII string in a web page, through the use of 
type="file" ... > tag (with a "browse" button). This string is caught as is by
R through the Rpad interface (using tcltk as a mini local webserver).

So it is not manually input by the user. As it appears in a textfield on a web
page, I could of course ask the user to change it manually and double the
antislashes. But this is not user-friendly.

>> Note that I have no control on the string which is returned from the 
>> system (no such problem under Linux BTW).
> Really?  What happens with file names containing backslashes on Linux?

I just meant no conversion was needed under Linux since pathnames use slashes.
That's why I didn't see this problem until I had my student use the graphical
interface under Windows.

Thank you,


More information about the R-help mailing list