How to set path in R in windows operating system using r'path\to\directory'?

963 Views Asked by At

In windows operating system (OS), for python, I can use os.chdir(r"path\to\directory\"). Is there any way that I can set the path in R also in similar way?.

One of the way known to me is setwd(readClipboard()). (Taking path in clipboard, Ctrl+C).

The purpose of the question is that, I need to everytime change the symbol \ to / to set the path in Windows OS.

1

There are 1 best solutions below

0
Donald Seinen On BEST ANSWER

R uses raw string syntax similar to C++,

r"(path\to\directory)"

or

setwd(R"(path\to\directory)")

with some further examples from ?Quotes:

r"(c:\Program files\R)"

## More raw strings:
r"{(\1\2)}"
r"(use both "double" and 'single' quotes)"
r"---(\1--)-)---"