Running RStudio and Setting Up Your Working Directory - Like shooting fish in a barrel R Programming

  • Use R exterior RStudio
    • Under Windows and MAC OSX
    • Under Linux
  • Use R inside RStudio
    • Launch RStudio under Windows, MAC OSX and Linux
    • Fix your working directory
      • Change your working directory
      • Set a default working directory
  • Shut your R/RStudio session
  • Related manufactures
  • Infos

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

Note that, it'southward possible to use R outside or within RStudio. However, nosotros highly recommend to use R inside RStudio. RStudio allows users to run R in a more convenient environment.

Apply R outside RStudio

Under Windows and MAC OSX

For the first fourth dimension you lot 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, volition be used by R to read and salve 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 beat prompt

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

$ mkdir R $ cd R

  1. Start the R programme with the command "R":

$ R

  1. To quit R programme, utilize this:

$ q()

Apply R inside RStudio

Using R inside RStudio is the recommended selection.

Launch RStudio nether Windows, MAC OSX and Linux

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

RStudio screen

RStudio

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

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

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

  3. Top-correct 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. Bottom-right panel:
    • Files tab: show files in your working directory
    • Plots tab: show the history of plots you created. From this tab, you tin can export a plot to a PDF or an paradigm files
    • Packages tab: bear witness external R packages available on your organization. If checked, the package is loaded in R.

For more than most RStudio read the online RStudio documentation.

Gear up your working directory

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

Change your working directory

You lot can change your working directory every bit follow:


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

  2. From RStudio, utilise the menu to alter your working directory under Session > Set Working Directory > Choose Directory.
  3. Choose the directory you've just created in stride 1

RStudio change working directory

It's also possible to use the R function setwd(), which stands for "prepare working directory".

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

For Windows, the command might wait like :

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

Notation 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 bill of fare under: Tools –> Global options –> click on "Browse" to select the default working directory yous want.

Close your R/RStudio session

Each time you shut R/RStudio, you will be asked whether y'all want to salvage the information from your R session. If you lot decide to save, the data will exist 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 help it spread by emailing information technology to a friend, or sharing it on Twitter, Facebook or Linked In.

Prove me some love with the like buttons below... Thanks and delight don't forget to share and annotate 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 north'oubliez pas, southward'il vous plaît, de partager et de commenter ci-dessous!