MC³ LabCUHK Psychology

Lesson 0 · Getting started

Set up

Install R and RStudio, and make a folder for the course.

In this lesson

  • Install R, then RStudio
  • Make an RStudio Project

Two programs

RThe engine

Does the work: reads data, runs statistics, draws charts.

RStudioThe dashboard

The window you work in. It runs R for you.

You need both. Install R first, because RStudio needs it.

Both are free.

Step 1: Install R

  1. Go to https://cran.r-project.org.
  2. Click Download R for Windows or Download R for macOS.
  3. Windows: click base, then the top link (Download R-4.x.x for Windows). Mac: pick arm64 for Apple M1/M2/M3/M4 chips, x86_64 for Intel. (Apple menu > About This Mac shows your chip.)
  4. Open the downloaded file and click Next / Continue until it finishes.

Step 2: Install RStudio

  1. Go to https://posit.co/download/rstudio-desktop/.
  2. Click Download RStudio Desktop.
  3. Windows: run the file. Mac: drag RStudio into Applications.

From now on, always open RStudio, not R.

Step 3: Check it works

Open RStudio. Click in the Console panel (left), type this and press Enter:

Type in the Console
1 + 1
Output
[1] 2

You see [1] 2? You're ready.

Step 4: Make a course folder

An RStudio Project is a folder that RStudio treats as home. Files you save go there, and R looks there for data.

  1. File > New Project... > New Directory > New Project
  2. Name it learn-r, choose where to save it (e.g. Documents), click Create Project.
  3. In the Files tab (bottom right), click New Folder and make a folder called data.
learn-r/
├── learn-r.Rproj    ← double-click to open the project
└── data/            ← put data files here

Each lesson tells you which data file it needs. Save it in data.

Next time, open the project with File > Open Project... or double-click learn-r.Rproj.