# How do I convert Windows Explorer file path to required file path format in R?

I keep having to manually convert my back slashes to front slashes. Is there a quick way of doing this through a function in R?

Example, copied from Windows Explorer:

G:\Compensation Audits_Reports\Step Audit\Steps off Step.accdb


R snippet example:

testdb<-file.path("G:/Compensation Audits_Reports/Step Audit/Steps off Step.accdb")

• maybe I shoudl have stripped of the examples to make it more generic looking? – daniellopez46 Jun 14 '12 at 21:19
• No, the examples are good and important. That didn't mean to coma across that negative but you have to understand that often, users who are question banned or suspended post their questions on other sites, and the community tries to migrate them back where they belong, only to find out that it's blocked by the system, which is just confusing. – slhck Jun 14 '12 at 21:31
• But how am I off topic when what I was asking for was a function not someone to edit my code? Its the same as other posts that exist out there and they were not closed. Examples: 1. Example1 2.Example2. – daniellopez46 Jun 14 '12 at 21:48
• I think in this case the question should be reopened, so I'm doing that. – nhinkle Jun 15 '12 at 0:23
• See stackoverflow.com/a/8425591/903061 for a neat solution. – Gregor Feb 27 '13 at 0:05

Using sub function, you can do
sub("\\\\","/","G:\\Compensation\\Step Audit\\Steps off Step.accdb")

It seems this is actually not possible because the windows paths are understood by R in such a way that the "\" escape the next character. Something like: "foo\bar" is perceived as some characters (foo) followed by the special \b character followed by some other, normal characters (ar).
To transform single "\" to "/" you first have to escape them by a backslash which would look like this: "foo\\bar" , which in the most cases is ridiculous because then you can as well transform the backslashes to slashes manually.