The R App
When you install R, you also get a small graphical application bundled with it: R.app on macOS and Rgui on Windows. It gives you an R console plus a simple editor for writing scripts, without installing anything else. It is the quickest way to start writing R on your own machine.
Opening the R App
- Open Finder and go to the Applications folder.
- Double-click R (the blue R icon). This is
R.app. - You can also press ⌘ + Space to open Spotlight, type
R, and press Enter.
If you have both R.app and R64.app, either one is fine on a modern Mac.
- Click the Start menu and type
R. - Choose R x.y.z (the version number will match what you installed). This opens
Rgui. - You can also find it under All Apps → R → R x.y.z.
If Windows shows both R i386 and R x64, choose R x64.
When the app opens you will see the R console with the > prompt. Type an expression and press Enter to run it:
2 + 2Writing an R script
The console is good for one-off commands, but anything you want to keep should go in a script — a plain text file with the .R extension that holds a sequence of R commands.
To open a new, empty script:
- macOS: File → New Document, or press ⌘ + N.
- Windows: File → New script, or press Ctrl + N.
An editor window opens. Type your code there, one command per line:
x <- c(4, 8, 15, 16, 23, 42)
mean(x)Nothing runs as you type. To run a line, put your cursor on it and press:
- macOS: ⌘ + Enter
- Windows: Ctrl + R
To run several lines, select them first and use the same shortcut. The commands are sent to the console, where you will see the output.
Saving your script
Save early and often.
- macOS: File → Save, or ⌘ + S.
- Windows: File → Save, or Ctrl + S.
In the save dialog:
- Choose a folder you can find again — a
stat133folder in your Documents is a good habit. - Give the file a short, descriptive name with no spaces, ending in
.R, such asvector-practice.R. - Click Save.
To reopen it later, use File → Open Document (macOS) or File → Open script (Windows) and select the file.
Tips
- Use
#to start a comment. Everything after it on that line is ignored by R. - Keep the script as the record of what you did; treat the console as scratch paper.