Academic Resource Center

Getting Started: R and RStudio, Part One

Updated on

Part 1

Welcome to the R and RStudio tutorial!

R is a programming language designed for statistical computing and graphing, and it is often used for data analysis and data visualization. Understanding R studio will help you succeed in programming with R, so let’s get started!

*Already know about RStudio and want to get into more detail? Start here.

1. Open RStudio and examine its four main panels.

Getting Started with R and RStudio 1.pdf - Google Drive - Google Chrome

The top left panel, panel 1, is where we write scripts that can be executed line by line or in chunks, when you highlight several lines.

Beneath this panel, panel 2, is a Console that displays the output of the scripts provided in panel 1. The Console is also helpful for writing and executing R codes one line at a time.

Panel 2 is also a place where R displays error messages.

Note: while you are a student, encountering error messages is a common practice and a great way to learn the R programming language. Give yourself some time to analyze the received errors and determine what is wrong with the codes. Dr. Thierry Warin is an excellent source to learn common mistakes in R that can help you understand R processes.

To the right of panel 2, you will see panel 3 which houses the following tabs or windows: Files, Plots, Packages, Help, and Viewer. Each of these windows has a specific purpose, but if the script outputs a graph, it is indeed shown in the Plots window.

Getting Started with R and RStudio 1.pdf - Google Drive - Google Chrome

The Packages window on panel 3 houses codes written by somebody else, and they provide extra functionality to the R programming language.

Do not expect to know all the R packages, and allow yourself time to learn this extra functionality as you patiently grow knowledge of the R programming language.

But, while you have the Packages window open, scroll down to see that some of the packages have a check-mark next to them, meaning that this package is installed on your particular computer.

Getting Started with R and RStudio 1.pdf - Google Drive - Google Chrome

Scroll down and find the ggplot2 package. Place a check-mark next to it and observe the change in the Console. I bet you see the >library(ggplot2)! Instead of declaring the package in the working script, RStudio allows selecting the packages you need for the data analysis interactively. Come back to the Packages view and click on ggplot2. It will bring you to the Help window with a description of the ggplot2 package. After the version number in the Packages view of the ggplot2, you can find a link to the package website to learn more about the package (see the red arrow in the image above).

Another essential window in panel 3 is Files, which allows you to navigate your working R files quickly and efficiently.

It is a good habit to set up a working directory where R can store and access the files of the current session.

Let’s try it right now! You can use the Console to issue the following codes:

Getting Started with R and RStudio 1.pdf - Google Drive - Google Chrome

Notice the output path on your computer and understand that this path will undoubtedly be different from the one displayed in my output, but the process to get and set the working directory is the same.

Let’s say I want to change the working directory to another folder named “Getting Started with R.” I can easily change it by issuing the following codes:

> setwd(“C:/Users/asb16/OneDrive/Documents/_development/r-workspace/Getting Started with R”)

Use getwd() again to verify the change, as illustrated below.

Getting Started with R and RStudio 1.pdf - Google Drive - Google Chrome

Another window in RStudio that provides valuable information to the user is the Environment, which you can find on the top right panel, panel 4. It lists all the variables created so far in the current session.

Let’s move on to Getting Started with R and RStudio, Part 2, to get more familiar with R.

Need More Help?

Click here to schedule a 1:1 with a tutor, coach, and or sign up for a workshop. *If this link does not bring you directly to our platform, please use our direct link to "Academic Support" from any Brightspace course at the top of the navigation bar. 

Previous Article If/Else Statements in Python
Next Article Getting Started: R and RStudio, Part Two
Still Need Help? Schedule a service in the Academic Support Center