Setting Up a Working Directory in R
When beginning to work with R code, the first thing that you need to do is setup a working directory. A working directory is a location on your computer from which R will read and write files to. You can choose any location/folder on your computer where you want to save your code and set that as the working directory.
The following example shows how to set the working directory in R to the folder "C:\r-programming\data" on the C drive in Windows.
1# Set the working directory
2setwd("C:/r-programming/data")
3Note: You need to first create a directory called r-programming and then another directory within it called data. Check that you are able to access this directory C:/r-programming/data from Windows Explorer. Once the directory exists, you will be able to use the command to set that as the working directory.
Test Your Knowledge
Check your understanding of this lesson with a short quiz.
