# Set working directory (replace this with your own)
setwd("/Users/yourname/Desktop/filename/filename")
Setting up a Working Directory
It is important to keep all the files associated with a given project, such as data, scripts, analytical results, and figures, together. To do this we need to make a working directory.
To create a new working directory in RStudio:
- Use File → New Project or use the New Project button (available on the Projects toolbar in the top right corner or on the global toolbar at the top left corner).
- This will open the “New Project Wizard” popup.
- Click “New Directory”.
To set the working directory, there are two possible ways, using code or using RStudio directly:
Option 1: Using R Code
Option 2: Using RStudio Interface
On the top of the RStudio menu, click on Session.
Click Set Working Directory.
Then click To Source File Location.
To check if the working directory is set correctly, use the following code:
#| eval: false
#| include: true
# Returns the filepath of the current working directory
getwd()
[1] "/Users/haleydaarstad/Dropbox/GitHub/pol51_R"