statistics

R: navigating directories in R on Windows

r logo

R is an open source implementation of S-Plus language. There is a nice RGUI for windows, and following the excellent tutorials can be cumbersome if you don't know how to establish what is the working directory and how to navigate around. So here is this mini tutorial of sorts.

After R installs, the default working directory is My Documents folder. To confirm this, type

getwd()

and you should see where you are. To move around, you use

setwd()

Two issues on using this function when you are working in windows. First, to move around, you will need backslashes for the path separator. This is confusing since when you enter getwd(), the path that you get has forward paths, for example,

c:/development/rscripts

Attempting to move around using forward slashes will get you errors. You got to use escaped backslashes. Example:

setwd("c:\\bin")

Second, it is not clear, but you can actually use setwd() as cd. So you can navigate up and down directories via statements like this:

setwd("..\\Desktop")
setwd("..\\..\\fantasy\\directory")

Syndicate content