R Console

The Console in RStudio includes a variety of features intended to make interactively working with code more productive and straightforward. This documentation reviews these features. Learning to use these features along with the related features available in the Source pane can have a substantial payoff in your overall productivity.

Code completion

RStudio supports the automatic completion of code using the Tab key. For example, if an object named pollResults exists in the workspace, typing poll in the R console and then pressing the Tab key automatically completes the full name of the object.

The code completion feature also provides inline help for functions whenever possible. For example, typing med and then pressing Tab would result in a popup of possible auto-completion:

A screenshot of the RStudio console displaying tab-completion of the median function.

Code completion also works for function arguments, so typing median( and then pressing Tab will result in the possible arguments being displayed:

Code completion of variables within the median function, displaying the 'x', 'na.rm' and '...' function arguments.

Retrieving previous commands

As with the standard R console, the RStudio console supports the ability to recall previous commands using the arrow keys:

  • Up — Recall previous command(s)

  • Down — Reverse of Up

To reuse recently executed commands, use the Ctrl+Up shortcut to review the list (on Mac Command-Up) and then select a command from this list by pressing Enter:

A screenshot of the history of commands executed in the RStudio console.

The same keyboard shortcut can quickly search for commands that match a given prefix. For example, to search for previous instances of the glimpse function start typing glimpse and then press Ctrl+Up (on Mac Cmd+Up):

A screenshot of the R console in RStudio, showing a filtered list of executed commands that match 'glimpse'

Console title bar

The screenshot below illustrates a few additional capabilities provided by the Console title bar:

  • Display of the current version of R and working directory.

  • The ability to interrupt R during a long computation.

  • Minimizing and maximizing the Console in relation to the Source pane (using the buttons at the top-right or by double-clicking the title bar).

  • There are two additional tabs Terminal and Background Jobs which are covered in the Terminal and Background Jobs sections of the User Guide.

A screenshot of R console menu bar, showing the red 'stopsign' indicating the ability to stop the currently executed R code

Keyboard shortcuts

Beyond the history and code-completion oriented keyboard shortcuts described above, there are a wide variety of other shortcuts available. Some of the more useful shortcuts include:

  • Ctrl+1 — Move focus to the Source Editor

  • Ctrl+2 — Move focus to the Console

  • Ctrl+L — Clear the Console

  • Esc — Interrupt R

  • Ctrl+Shift+F10 or Cmd+Shift+F10 (Mac) - Restart R

  • Ctrl+Up or Command-Up on Mac — Display recently executed commands from the console

For a full list of shortcuts, see the Shortcuts reference page.