Is there a way to make Windows return the path to a directory like Linux?… here is a solution to the problem.
Is there a way to make Windows return the path to a directory like Linux?
In Windows, the path to a directory is similar to:
C:\username
In Linux it should look like this:
/home/name
In the R programming language, backslashes are escape characters, so the path, even on Windows systems, must be written as C:/Users/Name or C:\\Users\\Name. When the path is too long, re-entering each slash is quite tiring.
Anyway, will Windows return a path with a double backslash or a single slash?
If not, is there an easy way in R to change the path so that R can understand it?
Thank you so much.
Solution
If you are running interactively, you can copy the Windows path to the clipboard and then use:
normalizePath(readClipboard(), "/")
This returns a Unix-style path.
Example C: \Users\john\Dropbox
. Highlight right-click and copy in window. Then run:
> normalizePath(readClipboard(), "/", mustWork = FALSE)
[1] "C:/Users/john/Dropbox"