Skip to main content Link Menu Expand (external link) Left Arrow Right Arrow Document Search Copy Copied

Lesson 0 - Using RStudio

This lesson will go over some of the functionality and features that RStudio provides.

Table of Contents

Lesson Objectives

  • Understand how to use RStudio

RStudio

A typical RStudio window has 4 important sections. The source code, the console, the environment, and a fourth section for files, plots, packages, or help.

RStudio window

Source Code

This is the section where you’ll be writing all your R code. You can also save your R code to a file to come back to it easily.

source code

If you don’t see this section, go to File > New File > R Script. This should make the source code section appear.

creating a new R script

Console

The console will show you the output of your code and any errors that you may come about. You can also type R commands directly into the console to run them.

console window

Environment

In the environment section, you can see all currently stored data. If you want to start from a clean slate, you can use the brush button to wipe your environment clean.

environment variables

Other

This last section has everything else you might need. A file explorer window, an area to view plots/graphs, a list of currently installed packages, and a section to get help.

other tabs

Creating and Running Code

Any code you want to be able to rerun in the future should be written in the source code area and saved to a file.

To run a line of code, click on the line you want to run and click on the Run button.

running code in R

Alternatively, you can also use the Ctrl + Enter keyboard shortcut.

If you want to run multiple lines of code at once (or the entire file), highlight the portions you want to run and use the Run button (or the shortcut) to run the code.

If you want to work with your data interactively, you can also run R commands in the console. This is most useful for testing and debugging purposes.

using the console interactively

Installing Packages

Packages are extensions to the R programming language. They provide additional functionality, whether that be datasets or functions. With R, you have access to ~20,000 packages.

To install packages in R, navigate to the Packages section in the bottom right area. You’ll see a list of enabled and disabled installed packages. If you don’t see the package you want, you can click on the Install button and search it by name.

installing packages using CRAN

Getting Help

To get help with anything in the R programming language, you can use the help panel.

If you need help with a particular function, type ?functionName in the console. This will open up the function’s help page.

getting help

Key Points / Summary

  • RStudio brings a lot of features to help with programming.
  • You can type ?functionName to get a help page for that function.