1

Quick one - I am a beginner in R Studio so trust asking a silly question .

What is the difference between the two code of setwd as not sure ? or is their any difference at all ?

> setwd("C:/Users/RAMIT PAUL/Downloads/Rate Cat")
> setwd("C:\\Users\\RAMIT PAUL\\Downloads\\Rate Cat")
zx8754
  • 693

1 Answers1

0

Any number of forward slashes will work (this is an OS thing). So the both the following will work:

setwd("C:/Users/RAMIT PAUL/Downloads/Rate Cat")
setwd("C://////////Users///////////RAMIT PAUL///////////Downloads///////////Rate Cat")

Now, backslashes are imbued with special meaning. They are used for escape sequences. So you have to escape the slash itself so it's correctly parsed. Hence, this won't work:

setwd("C:\Users\RAMIT PAUL\Downloads\Rate Cat")

While these work:

setwd("C:\\Users\\RAMIT PAUL\\Downloads\\Rate Cat")
setwd("C:\\\\\\\\\\\\\\\\\\\\\\Users\\RAMIT PAUL\\Downloads\\Rate Cat")

In R 4.0.0 you can actually use (thanks Mossa):

setwd(r"(C:\Users\RAMIT PAUL\Downloads\Rate Cat)")
Firebug
  • 472
  • @user817995 You're welcome :). Please consider accepting my answer (clicking the green check mark below the score arrows) if it thoroughly answered all your inquiries. – Firebug Feb 19 '18 at 12:56
  • 1
    Also add the setwd(r"(C:\Users\RAMIT PAUL\Downloads\Rate Cat)") that was introduced in R 4.0. See this – Mossa May 10 '22 at 12:02
  • 1
    Cool, thanks for the tip @Mossa! I haven't kept up with new R changes, that is nice to have – Firebug May 10 '22 at 12:14