background picture with networks
Module 1 | Lesson 5

Ditch setwd() - Use RStudio projects

RStudio projects make it straightforward to make your data analysis isolated in its own working environment.

Each project will have its own working directory, workspace and source documents.

Members only
9 minutes read

Problem: the setwd() nightmare

When you are working with R, your code run in a folder called the current directory.

This is the folder in which R looks for files. You can check what's the current directory with the following command:

getwd()

# -> /Users/holtzy/Desktop/

Give it a go!

Type the above command in your R console.


You can decide what directory to work in, and then read a file in this directory. It often looks like this:

# Set the working directory
setwd("/Users/holtzy/Desktop/") 

# Ask R to read a file that is located in this directory
data <- read.csv("data.csv")

It works!

But then perhaps you want to move your project folder from Desktop to Document. Or somebody else wants to run your code on his machine?

background picture with networks
Productive R Workflow

This lesson is for members only! 😔
Become a member now to access the full course with a lifetime access!

Or Login

← Previous

Self contained project

Next →

Never ever modify raw data