What is R? What is RStudio?

The term “R” is used to refer to both the programming language and the software that interprets the scripts written using it.

RStudio is a popular way to write R scripts and interact with the R software. To function correctly, RStudio needs R and therefore both need to be installed on your computer.

Knowing your way around RStudio

RStudio is divided into 4 “panes”:

  • The Source for your scripts and documents (top-left, in the default layout)
  • Your Environment/History (top-right) which shows all the objects in your working space (Environment) and your command history (History)
  • Your _Files/Plots/Packages/Help/Viewer (bottom-right)
  • The R Console (bottom-left)

Interacting with R

Programming involves writing instructions for the computer to follow, which are coded in a common language like R that both the computer and humans can understand. These instructions, also known as commands, are executed or run by the computer.

There are two primary ways to interact with R: through the console or by using script files, which are plain text files containing code. The console pane, typically located in the bottom left panel of RStudio, allows you to type and immediately execute R commands. However, commands entered directly into the console are not saved when the session is closed.

To ensure reproducibility and maintain a record of your work, it’s preferable to type commands in the script editor and save the script. This way, you have a complete record of your actions, and others can easily replicate your results.

In RStudio, you can execute commands from the script editor using the Ctrl + Enter shortcut (Cmd + Return on Mac). This sends the command on the current line or all selected text to the console for execution. Additionally, keyboard shortcuts like Ctrl + 1 and Ctrl + 2 allow you to switch between the script and console panes.

When R is ready to accept commands, the console displays a > prompt. After receiving a command, R executes it and displays the results, followed by a new > prompt. If R is still expecting input to complete a command (indicated by a + prompt), you can cancel the incomplete command by pressing Esc.