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

  • Apply R outside RStudio
    • Under Windows and MAC OSX
    • Under Linux
  • Employ R inside RStudio
    • Launch RStudio under Windows, MAC OSX and Linux
    • Fix your working directory
      • Modify your working directory
      • Fix a default working directory
  • Close your R/RStudio session
  • Related articles
  • Infos

After installing R and RStudio, the question is now how to starting time using R/RStudio. In this commodity, we'll draw how to run RStudio and to set up your working directory.

Note that, it'south possible to utilise 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 environs.

Use R exterior RStudio

Nether Windows and MAC OSX

For the get-go fourth dimension you lot utilize R, the suggested procedure, nether Windows and MAC OSX, is as follow:

  1. Create a sub-directory, say R, in your "Documents" folder. This sub-folder, besides known equally 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 up 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 plan, 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 "awarding folders".

RStudio screen

RStudio

RStudio is a 4 pane work-space for 1) creating file containing R script, ii) typing R commands, iii) viewing control histories, 4) viewing plots and more than.

  1. Top-left panel: Lawmaking editor assuasive you to create and open a file containing R script. The R script is where you proceed a record of your work. R script tin can exist created equally follow: File –> New –> R Script.

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

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

For more near 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

Yous tin change your working directory as follow:


  1. Create a sub-directory named "R" in your "Documents" binder

  2. From RStudio, utilize the carte du jour to change your working directory nether Session > Ready Working Directory > Choose Directory.
  3. Choose the directory you've merely created in step 1

RStudio change working directory

Information technology'due south also possible to use the R part setwd(), which stands for "prepare working directory".

                      setwd("/path/to/my/directory")                    

For Windows, the control might look like :

                      setwd("c:/Documents/my/working/directory")                    

Notation that, if yous desire to know your current (or default) R working directory, type the command getwd(), which stands for "get working directory".

Gear up a default working directory

A default working directory is a folder where RStudio goes, every time y'all open it. You can alter the default working directory from RStudio menu nether: Tools –> Global options –> click on "Scan" to select the default working directory you want.

Shut your R/RStudio session

Each time you lot close R/RStudio, you will exist asked whether you desire to save the information from your R session. If you determine to save, the data will be available in future R sessions.

Infos

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


Enjoyed this article? I'd be very grateful if you'd aid information technology spread past emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.

Show me some love with the like buttons below... Cheers and please don't forget to share and comment below!!

Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.

Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!