In R, how to change working directory more easily?

562 Views Asked by At

In how to change working directory more easily? Currently, if we use 'setwd',we have to add many '\', sometimes it's boring Is there any easier way for this ? (Just like Python can add 'r' )

setwd('C:\Users\Administrator\Desktop\myfolder') # can't work
setwd('C:\\Users\\Administrator\\Desktop\\myfolder') # can work,but havt to add many '\'
1

There are 1 best solutions below

0
U13-Forward On BEST ANSWER

You could use r (for raw string) and add parenthesis:

> r"(C:\Users\Administrator\Desktop\myfolder)"
[1] "C:\\Users\\Administrator\\Desktop\\myfolder"
> 

And now:

setwd(r"(C:\Users\Administrator\Desktop\myfolder)")

Or reading from clipboard automatically adds the extra slashes:

setwd(readClipboard())