This tutorial is an attempt to explain beginners how to install, run, and use RStudio. Unlike many of the beginners’ assumption, Both R and RStudio are two different applications/software. One need to install R first. RStudio is a separate piece of software that works with R to make R much more user friendly with some helpful features that make your R programming easier and more efficient.

RStudio runs in windows mac and Linux and even over the web using RStudio Server. It is advisable to learn to use R, especially if you will be dealing with statistical operations, where you may be expected to know how to use it.

This tutorial will cover the following topics

How to install R Studio

Installing R
Go to R Project website and download R for your operating system.

Installing R Studio
Go to RStudio website and click on “Download RStudio” and follow the directions for your operating system.

Launching RStudio

Open RStudio by clicking on the RStudio desktop icon. You’re ready to go!
R Studio is an integrated development environment (IDE) for R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management.

When you launch RStudio, you will see the following four windows or panes.

  1. Source
  2. Console
  3. Environment/History
  4. Files/Plots/Packages/Help

Let’s see about each window briefly:

Source

The source pane is where you create and edit R Scripts” – your collections of code. R scripts are just text files with the “.R” extension. When you open RStudio, it will automatically start a new Untitled script. Before you start typing in an untitled R script, you should always save the file under a new file name. That way, if something on your computer crashes while you are working, RStudio will have your code waiting for you when you re-open RStudio, as it has recovered the code that you were editing.

Console

The console is the heart of R. By default, It is present at the bottom left of the window. It is also called a command window. Here is where R actually evaluates code. At the beginning of the console you will see the character. This is a prompt that tells you that R is ready for new code. You can type code directly into the console after the prompt and get an immediate response, just like any REPL.
For example, if you type 3+5 into the console and press enter, you will see that R immediately gives an output of 8.

3+5
8

Environment/History

The Environment tab of this panel shows you the names of all the data objects (like vectors, matrices, and dataframes) that you have defined in your current R session. You can also see information like the number of observations and rows in data objects. As you get more comfortable with R, you might find the Environment / History panel useful. you can also declutter the panes in the screen, or just minimize the window by clicking the minimize button on the top right of the panel.
The history window shows all commands that were executed in the console.

Files/Plots/Packages/Help

By default, This is located at the bottom right of the window and it shows you lots of helpful information. Here you can open files, view plots, install and load packages, read main pages, and view markdown and other documents in the viewer tab.

Let’s go through each tab in detail:

Files
The files panel gives you access to the file directory on your hard drive. One nice feature of the “Files” panel is that you can use it to set your working directory – once you navigate to a folder you want to read and save files to, click “More” and then “Set As Working Directory.” We’ll talk about working directories in more detail soon.

Plots
The Plots panel shows all your plots. There are buttons for opening the plot in a separate window and exporting the plot as a pdf or jpeg (though you can also do this with code using the pdf() or jpeg() functions.)

Sample Plot

plot(iris)

Gives this plot:

Packages
Shows a list of all the R packages installed on your hard drive and indicates whether or not they are currently loaded. Packages that are loaded in the current session are checked while those that are installed but not yet loaded are unchecked. Packages can also be installed using the command (in console), like this one below:

install.packages("tidyverse")

Help
Help menu for R functions. You can either type the name of a function in the search window or use the code to search for a function with the name.

Advantages of R Studio

One of the main advantages of R is that, If the function you want isn’t available you can write your own package and share it with the world.
RStudio includes powerful coding tools designed to develop and publish such packages. It also enhances productivity and supports authoring HTML, PDF, Word Documents, and slideshows too. RStudio also makes it easy to start new or find existing projects.

Exiting R Studio

You can exit both at the same time using File => Quit R Studio Or you can type q() at the command prompt. Note that this is the letter q followed by open and closed parentheses. It is recommendable to use RStudio if you can, at least to get started – it makes it easier to work in R.