R Get Started

Getting started with R means installing R itself, adding RStudio as your editor, and running your first lines of code.

Installing R

R is free to download from CRAN (the Comprehensive R Archive Network) at cran.r-project.org. Installers are available for Windows, macOS, and Linux, and the base installation includes the R console, the core language, and a standard set of built-in packages.

Installing RStudio

R by itself only gives you a bare console. Almost everyone pairs it with RStudio, a free integrated development environment (IDE) that adds a code editor, a file browser, a variable viewer, and a panel for viewing plots, all in one window. You install R first, then install RStudio, which detects your existing R installation automatically.

  1. Download and install R from CRAN for your operating system
  2. Download and install RStudio Desktop (the free edition)
  3. Open RStudio — it will locate your R installation automatically
  4. Open the Console pane and try typing a command
PanePurpose
SourceWhere you write and save .R script files
ConsoleWhere code actually runs, one command at a time
EnvironmentLists the variables you have created in the current session
Plots / Files / HelpShows charts, project files, and documentation

Running Your First Command

You can type code directly into the Console and press Enter to run it immediately, which is great for quick experiments. For anything you want to save and reuse later, write it in a script file with a .R extension in the Source pane instead.

Example

print("Hello, World!")
1 + 1
Note: In the Console, you don't always need print() for a bare value — typing 1 + 1 and pressing Enter shows [1] 2 automatically. print() becomes necessary inside scripts, loops, and functions, where results are not auto-printed.

Save your code in a file such as my_script.R, then run the whole file with the Source button in RStudio, or run just the current line and move to the next with Ctrl+Enter (Cmd+Enter on macOS).

Note: Use getwd() to see R's current working directory and setwd() to change it — this affects where R looks for files and where it saves output by default.

Exercise: R Get Started

What best describes RStudio in relation to R?