Setting Up Your Development Environment
Prerequisites: Installing R and RStudio
RStudio's window has four panes:
- Console (bottom left) — type R code and press Enter to run it immediately. Great for quick experiments.
- Source editor (top left) — write scripts (
.Rfiles) you can save and run again. Put anything you'll want to keep here. - Environment (top right) — shows the variables you've created.
- Files / Plots / Packages / Help (bottom right) — browse files, see charts, manage packages, and read documentation.
Scripts and running code
Create a script with File → New File → R Script. To run code:
- Ctrl + Enter (⌘ + Enter on macOS) runs the current line or the selection.
- Ctrl + Shift + Enter runs the whole script.
Projects
Use File → New Project to create an RStudio Project for each analysis. A project keeps your scripts, data, and outputs together in one folder, and sets the working directory — the folder R reads and writes files from — automatically. This avoids the classic "file not found" problem.
Getting help
Put ? before a function name to open its help page, including
examples at the bottom:
?mean
??regression searches all help pages for a word.
A good habit
In Tools → Global Options → General, turn off "Restore .RData into workspace at startup" and set "Save workspace to .RData on exit" to Never. Starting each session fresh ensures your scripts really contain everything needed to reproduce your results.