RStudio Setup
In this guide, I will walk you through the recommended setup for RStudio. Most of these adjustments are cosmetic and entirely optional: they make RStudio more comfortable to work in, but we will get the same R programming results either way. The exception is the workspace setting in the General section, which deliberately changes what R loads at the start of every session, so please do not skip that one.
First open the settings dialogue:
- Windows:
Tools→Global Options... - Mac:
Tools→Global Options..., or pressCmd+,
Then work through the sections below. Each one names the pane on the left of the dialogue and the tab along the top, so you can find every option without hunting.
Only the options listed below need changing. Everything else can stay exactly as RStudio installed it, including any panes you don’t recognise such as Assistant or Sweave.
The exact wording and position of these options can vary slightly between RStudio versions and between Windows and Mac. If you cannot find one of the cosmetic options, just skip it. The restore options in the General section are worth hunting for, though — those are the ones that change how every session starts.
1 General
In the General pane, Basic tab:
- Untick
Restore most recently opened project at startup: stops RStudio reopening the last project you worked on. - Untick
Restore previously open source documents at startup: stops RStudio reopening the scripts you had open last time. - Untick
Restore .RData into workspace at startup: stops RStudio reloading the previous workspace, so every session starts from a clean slate. This is the single most important one — reloading an old workspace is a common source of results you cannot reproduce. - Confirm
Always save history (even when not saving .RData)is ticked. It is ticked by default, so you should not need to change it; it keeps a searchable record of the commands you have run.
2 Code
2.1 Editing
In the Code pane, Editing tab:
- Tick
Auto-detect code indentation: RStudio then follows the indentation already used in a file you open, instead of imposing its own.
2.2 Display
In the Code pane, Display tab:
- Tick
Highlight selected line: shades the line the cursor is on, so you can always see where you are. - Tick
Allow scroll past end of document: lets you scroll the last line of a script up to the middle of the screen, rather than it being stuck at the bottom edge. - Tick
Highlight R function calls: colours function names differently from variables, which makes it easier to read unfamiliar code. - Tick
Use rainbow parentheses: colours each pair of brackets differently, so an unbalanced bracket becomes obvious immediately. Very useful when nestingdplyrverbs.
2.3 Completion
In the Code pane, Completion tab:
- Tick
Show help tooltip on cursor idle: rest your cursor on a function and its arguments appear, without having to look up the help page. - Tick
Use tab for multiline autocompletions: letsTabcomplete names inside expressions that span several lines.
3 Appearance
Feel free to play around with the options here to adjust the appearance of RStudio to your preference.
4 R Markdown
4.1 Basic
In the R Markdown pane, Basic tab:
- Tick
Show document outline by default: shows the section outline next to your document, which makes long case studies far easier to navigate. - Set
Show output preview in:toViewer Pane: rendered documents then appear inside RStudio instead of opening a separate window. - Set
Show equation and image previews:toInline: shows equations and images in the editor as you write them.
4.2 Visual
In the R Markdown pane, Visual tab:
- Tick
Use visual editor by default for new documents: new.qmdfiles then open in the visual editor, which displays headings, lists and tables as formatted text rather than raw markdown. You can switch betweenSourceandVisualat any time using the buttons at the top left of the editor.