2. Working Directory

flowchart LR
    A["`**Step 1**
    Scripts & Projects`"] --> B["`**Step 2**
    Working Directory`"] --> C["`**Step 3**
    Libraries`"] --> D["`**Step 4**
    Import & Export`"]
    style B fill:#1a1a1a,stroke:#1a1a1a,color:#fff
    linkStyle default stroke:#adb5bd,stroke-width:2px

Working Directory

The working directory is the root folder location of your project. This is where R goes to find data, R scripts, and save data. There are two commands that will help you navigate your working directories: setwd() and getwd().

getwd() returns your current working directory and setwd() will set a new working directory file path.

Many frustrations with R are rooted in setting the right working directory file path. First, working directories are specific to each computer. setwd() sets an absolute path. There are ways to set relative paths, which we will discuss in further detail in the R projects section of this tutorial. Second, working directory file paths on machines running Windows use back slashes (\) while Macs use forward slashes (/).

You can manually set your working directory in RStudio by clicking Session >> Set Working Directory >> Choose Working Directory. Then you can navigate to a file path that you want to set as your working directory.

All of this can make your head spin, but as long as you make setting your working directory part of your initial workflow, it will become second nature in short order.

Which of the following allow you to set the working directory for your RStudio session?

The command setwd(user/documents/project_folder) returns an error. Identify all possible reasons the error message was generated: