Skip to Main Content
Go to Penn Libraries homepage   Go to Guides homepage

R for Business Guide

R and RStudio

R users typically work in RStudio. This IDE (Integrated Developer Environment) builds on the base R software to offer a more-accessible interface for everything from writing code to installing packages. If someone says they use R, they probably run RStudio as they program in the R language.

Console

In the default RStudio layout, you code and run code in the panes along the left.

Type in the Console and press the Enter key to run code line-by-line. You'll see a continuous log of code you've run followed by each line's output.

RStudio window running ?c in the Console

When you close R, the Console gets cleared; you'll start fresh next session. This is great if you need to run a line of code once, in the moment--like opening Help (?) to see how a function works.

File

If you want to run your code in the future, save it in a file. When you open a file, it appears above the Console.

Open or add a file using the File menu.

  • New File > R Script: Code only
  • New File > R Markdown: Code and formatted text
  • New Project: Folder that keeps related files (scripts, data, etc.) together

Script file

You can run code directly from an R Script file. Press Ctrl+Enter or Cmd+Enter to run the current line or a selected section.

RStudio, using the code file to save a vector to the Environment

Running code from the file enters and runs it in the Console. Your script file stays the same.

Output

RStudio, right panesDepending on its design, your code may print a result in the Console, change your system, or produce other output.

If you create an object (e.g.: dat <- c(1:5)), the object appears in the Environment in the upper right pane. Use any object stored in the Environment by typing its name in your code.

If you open Help or visualize your data, the result appears in the lower right pane.

Business & Data Analysis Librarian

Profile Photo
Kevin Thomas
He/Him/His
Subjects: Statistics

Chat

Penn Libraries Home Franklin Home
(215) 898-7555