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:
Code completion also works for function arguments, so typing median(
and then pressing Tab will result in the possible arguments being displayed:
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:
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):
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.
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.