Reputation: 465
In Windows a path to a directory is something like: C:\Users\Name
In Linux it should be something like: /home/name
In the R programming language backslashes are an escape character, therefore a path (even on a Windows system) must be written either as C:/Users/Name or C:\\Users\\Name. When the path is too long it is rather tiring to retype every slash.
Is there anyway in which Windows returns the path with double backslashes or one slash? If not, is there a simple way in R to change the path so that R can understand it?
Thank you very much.
Upvotes: 3
Views: 2102
Reputation: 697
to navigate through directories in R, you can also use the foldernames to get into a windows folder and .. to go back to the parent folder e.g.
setwd("new")
setwd("..")
Upvotes: 0
Reputation: 30435
If you are running interactively you can copy the windows path to the clipboard then use:
normalizePath(readClipboard(), "/")
This will return a unix style path.
Example C:\Users\john\Dropbox
. Highlight right click and copy in windows. Then run:
> normalizePath(readClipboard(), "/", mustWork = FALSE)
[1] "C:/Users/john/Dropbox"
Upvotes: 2
Reputation: 521944
Try this:
gsub("/", "//", getwd())
Output:
[1] "C://Users//tbiegeleisen//Documents"
Upvotes: 2