How to Set Your Working Directory in RStudio on a PC

This is a quick tip to avoid having to use the setwd() function to set your working directory all the time.

Assuming you are working on a PC using RStudio, here is how to change your working directory to a R sub-folder. To do this, I made use of this guide.

Step 1: Go to C:\Program Files\R\[your_version]\etc

In here you will find a file called ‘Rprofile.site’.

Step 2: Open this file in a text editor

It should have a number of options pre-loaded.

Step 3: Add a new command at the bottom

It should say something like the following, depending how your files are stored:

setwd("C:/Users/[user]/Documents/R")

Step 4: Restart RStudio

Step 5: run the getwd() function

It should change to your new directory!

Leave a Reply

Your email address will not be published. Required fields are marked *