Running RStudio and Setting Up Your Working Directory - Easy R Programming

After installing R and RStudio, the question is now how to start using R/RStudio. In this article, we’ll describe how to run RStudio and to set up your working directory.

Note that, it’s possible to use R outside or inside RStudio. However, we highly recommend to use R inside RStudio. RStudio allows users to run R in a more user-friendly environment.

Use R outside RStudio

Under Windows and MAC OSX

For the first time you use R, the suggested procedure, under Windows and MAC OSX, is as follow:

  1. Create a sub-directory, say R, in your “Documents” folder. This sub-folder, also known as working directory, will be used by R to read and save files.

  2. Launch R by double-clicking on the icon.

  3. Specify your working directory to R:
    • On Windows: File –> Change directory
    • On MAC OSX: Tools –> Change the working directory

Under Linux

  1. Open the shell prompt

  2. Create a working directory, named “R”, using “mkdir” command:

$ mkdir R $ cd R

  1. Start the R program with the command “R”:

$ R

  1. To quit R program, use this:

$ q()

Use R inside RStudio

Using R inside RStudio is the recommended choice.

Launch RStudio under Windows, MAC OSX and Linux

After installing R and RStudio, launch RStudio from your computer “application folders”.

RStudio screen


RStudio is a four pane work-space for 1) creating file containing R script, 2) typing R commands, 3) viewing command histories, 4) viewing plots and more.

  1. Top-left panel: Code editor allowing you to create and open a file containing R script. The R script is where you keep a record of your work. R script can be created as follow: File –> New –> R Script.

  2. Bottom-left panel: R console for typing R commands

  3. Top-right panel:
    • Workspace tab: shows the list of R objects you created during your R session
    • History tab: shows the history of all previous commands
  4. Bottom-right panel:
    • Files tab: show files in your working directory
    • Plots tab: show the history of plots you created. From this tab, you can export a plot to a PDF or an image files
    • Packages tab: show external R packages available on your system. If checked, the package is loaded in R.

For more about RStudio read the online RStudio documentation.

Set your working directory

Recall that, the working directory is a folder where R reads and saves files.

Change your working directory

You can change your working directory as follow:

  1. Create a sub-directory named “R” in your “Documents” folder

  2. From RStudio, use the menu to change your working directory under Session > Set Working Directory > Choose Directory.
  3. Choose the directory you’ve just created in step 1

RStudio change working directory

It’s also possible to use the R function setwd(), which stands for “set working directory”.


For Windows, the command might look like :


Note that, if you want to know your current (or default) R working directory, type the command getwd(), which stands for “get working directory”.

Set a default working directory

A default working directory is a folder where RStudio goes, every time you open it. You can change the default working directory from RStudio menu under: Tools –> Global options –> click on “Browse” to select the default working directory you want.

Close your R/RStudio session

Each time you close R/RStudio, you will be asked whether you want to save the data from your R session. If you decide to save, the data will be available in future R sessions.


This analysis has been performed using R software (ver. 3.2.3).

Want to Learn More on R Programming and Data Science?

Follow us by Email

by FeedBurner

On Social Networks:

 Get involved :
  Click to follow us on and Google+ :   
  Comment this article by clicking on "Discussion" button (top-right position of this page)
  Sign up as a member and post news and articles on STHDA web site.
This page has been seen 6271 times