2.2 The RStudio Interface

When you open RStudio, you’ll see an interface like the one shown below. It’s possible that the four windows highlighted in the image will be in a different order. Note that you can change the size of the windows by dragging the panes separating them.

RStudio Interface

FIGURE 2.1: RStudio Interface

2.2.1 Learning and experimenting in the console

The console, which defaults to the bottom left of R Studio, is your direct link to the underlying R software that actually executes commands.

To interact with the console, click your mouse inside the console pane. You should see a blinking cursor following the the symbol >. You then type a command and press the Enter key to execute it. The output from the command will be printed below.

As we will see, R can execute a huge variety of commands, but let’s start with a simple example: using R as a calculator. R is overkill for simple arithmetic, but it’s perfectly capable. For example, type 2+10/5 into the console and hit enter.

  2 + 10/5
## [1] 4

The console has two features that make it well suited for learning and experimentation:

  • The console prints output, like the result of the calculation above, so you can instantly see the results of your command.
  • It’s a convenient way to access R’s help and documentation features. Typing ?summary, for example, will quickly bring up the R help file on the summary() function. For more information about help and troubleshooting in R, see Section 2.6.

One way to use the console is to treat it as your scratch pad.

2.2.2 Writing R scripts in the source pane

The source pane is where you will build your analyses step by step. It defaults to the top left of R Studio and, although it is another way to issue commands to R, it works differently from the console.

The primary difference is that the source pane stores only commands and comments, not output. It is a specially tailored text editor, one of the conveniences offered by R studio. It allows you to save the precise “recipe” for an analysis in the form of a text file with a .R extension, known as an R Script.

Since R Scripts are a central way you will interact with R, we expand on how to create, execute, and save them in Section 2.3

2.2.3 The other panes

The environment pane displays the objects (dataframes, graphs, lists, etc) available. Finally, the plots/help panel displays your graphs, help files, and more. For example, load a built-in data frame and create a simple histogram. Type and execute the code below:

  IrisData <- iris

  hist(IrisData$Petal.Width)

Notice that the data frame IrisData is now listed in the environment pane. The histogram is displayed in the plot window.