Notice the default panes:
- Console (entire left)
- Environment/History (tabbed in upper right)
- Files/Plots/Packages/Help (tabbed in lower right)
NOTE: New tabs may show up in different contexts (e.g., Git tab)
Welcome to R & RStudio
An introduction to programming in R
NCEAS Learning Hub
RStudio IDE interface

Let’s take a tour of the RStudio interface!
RStudio IDE interface

Notice the default panes:
NOTE: New tabs may show up in different contexts (e.g., Git tab)
Quick Tip: You can change the default location of the panes, among many other things. More information here.
RStudio IDE interface

Console is where you can directly type R code.
When you start a new session, you’ll see some text that includes the current version of R software installed (yours may not match the image).
There are tabs for Terminal and Background Jobs. Terminal is direct access to your computer’s operating system (not R software).
RStudio IDE interface

Environment displays information in working memory - “objects” that may be individual values, lists or vectors with multiple values, data frames of tabular data, etc.
When you start a new session, the environment pane should say “Environment is empty.” As you use R to make calculations and store values, you will see objects in this pane.
There is a tab for History and perhaps others. History will show you the sequence of any commands you have typed or executed into R. When writing R scripts, the History tab is not necessary for reproducible science.
RStudio IDE interface

Files displays files and folders on your computer. You can navigate just like you would normally browse on your computer.
Note the other tabs in this pane: when you create plots or tables, they will generate in the plots pane. Packages provides information on the packages and versions installed, and Help is provides searchable documentation for those packages and functions. Viewer and Presentation display HTML or other outputs.
Coding in the Console
We run code in the Console.
At its most basic, we can use R as a calculator.
Let’s try a couple of examples in the console.
When you hit “enter” after the calculation, R immediately evaluates the expression and provides the result.
Coding in the Console
Quick Tip
In the console, a greater than sign (>) signals the start of a line. This is called the “prompt” and means R is ready to accept commands. If you see a plus sign (+) in the console, it means R is waiting for additional information. You can press escape (esc) to return to the prompt. Try practicing this by running 3* (or any incomplete expression).
Storing values in objects
The assignment operator (<-) creates an “object” by assigning it a name. R will evaluate the expression on the right side, and store that value with the name on the left.
For example, assign the result of 3 * 4 and call it “result”. Then we can call the name of the object to use the value in other calculations, and so on.
Storing values in objects
Here’s a slightly more complicated example to calculate the volume of a cylinder.
RStudio IDE interface

Now the Environment pane contains the objects and values we created in our example.
R scripts vs. console
While there are many cases where it makes sense to type code directly in to the the console, it is not a great place to write most of your code since you can’t save what you ran.
A better way is to create an R Script, and write your code there.
When you run your code from the script, you can save it when you are done, and you can re-run it later to get the exact same result - a key to reproducible science.