Working in the Console
Overview
The Console in the RStudio IDE includes a variety of features intended to make working with R more productive and straightforward. This article reviews these features. Learning to use these features along with the related features available in the Source and History panes can have a substantial payoff in your overall productivity with R.
Code Completion
The RStudio IDE supports the automatic completion of code using the Tab key. For example, if you have an object named pollResults
in your workspace you can type poll
and then Tab and RStudio will automatically complete the full name of the object.
The code completion feature also provides inline help for functions whenever possible. For example, if you typed sub
then pressed Tab you would see:
Code completion also works for function arguments, so if you typed subset(
and then pressed Tab you'd see the following:
Retrieving Previous Commands
As you work with R you'll often want to re-execute a command which you previously entered. 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
If you wish to review a list of your recent commands and then select a command from this list you can use Ctrl+Up to review the list (note that on the Mac you can also use Command-Up):
You can also use this same keyboard shortcut to quickly search for commands that match a given prefix. For example, to search for previous instances of the plot
function simply type plot
and then Ctrl+Up:
Console Title Bar
This screenshot illustrates a few additional capabilities provided by the Console title bar:
- Display of the current 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).
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
You can find a list of all shortcuts in the Keyboard Shortcuts article.
Comments