Skip to the workspace
Pebellslearn by building
Introduction and Setup  ›  Lesson

Installing R and Choosing an Editor

Installing R 10 minYou install R itself from CRAN, then use an editor such as RStudio, Positron or VS Code as the workspace that sends your code to R.

r programming / Installing R and Choosing an Editor

Explore each scene at your own pace.

01 · The rule

The rule

Installing R and Choosing an Editor

You install R itself from CRAN, then use an editor such as RStudio, Positron or VS Code as the workspace that sends your code to R.

Distinguish the R runtime from an editor and verify the version running your code.

A new volunteer installs RStudio, opens it, and is told that R cannot be found. This happens so often because R setup is really two installs: the language itself, and the program you type into. Once you see them as separate pieces, every setup problem gets easier to diagnose.

The rule

Install the engine from CRAN, then pick a dashboard to drive it.

The engine is R. It is the program that actually reads and runs your code. You download it from CRAN, the Comprehensive R Archive Network, a set of mirror servers around the world that hosts R and its packages (cran.r-project.org):

  • Windows: run the installer from the "base" download.
  • macOS: pick the installer that matches your chip: the arm64 build for Apple silicon (M-series) Macs, the x86_64 build for older Intel Macs.
  • Linux: use your distribution's package manager, such as sudo apt install r-base on Ubuntu or Debian.

Opening R gives you the console: a > prompt where you type an expression and see the answer.

> 1 + 1
[1] 2
> R.version.string
[1] "R version 4.x.y (...)"

The [1] is not part of the answer. It tells you that the first value on that line is element number 1, which helps when a long vector wraps over several lines.

If the prompt changes to +, R thinks your expression is not finished, usually because of a missing bracket or quote. Finish it, or press Esc to start again.

The dashboard is an editor, a program that holds your scripts and sends lines to R:

  • RStudio (by Posit): the classic choice, with four panes for scripts, the console, the environment (your variables) and files, plots and help.
  • Positron (also by Posit): a newer data-science editor built on the same open-source base as VS Code, working with both R and Python.
  • VS Code with the R extension: handy if you already use VS Code for other languages.

None of these include R. Each one looks for the R you installed.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.