How to Set Working Directory in R
If you want to read files from a specific location or write files to a specific location you will need to set working directory in R. The following example shows how to set the working directory in R to the folder “Data” within the folder “Documents and Settings” on the C drive.
# Set the working directory setwd("C:/Documents and Settings/Data")
Remember that you must use the forward slash / or double backslash \\ in R! The Windows format of single backslash will not work.
Here’s the official R-manual page on setting the working directory: http://stat.ethz.ch/R-manual/R-patched/library/base/html/getwd.html.
To learn more about the working directory in R, try the exercises in this introduction to R.
Thanks for reading! This website took a great deal of time to create. If it was helpful to you, please show it by sharing with friends, liking, or tweeting! If you have any thoughts regarding this R code please post in the comments.