Skip to main content

Install R for VS Code

Steps on this page

Why R?

R is the industry standard for statistical analysis, data visualization, and reproducible research in mass communications. In this course you write and run R inside VS Code with the R extension, the same editor you use for everything else, so your code, notes, and reproducible reports all live in one workspace.

In this course you’ll use R to:

  • Clean and analyze data from surveys and content analysis
  • Create publication-ready visualizations and reports
  • Build reproducible workflows for your research
  • Collaborate on data analysis projects

This guide installs R and wires it into VS Code. If you have not installed VS Code yet, do that first: Install VS Code.


What you’ll install

  1. R itself (the programming language)
  2. The R extension for VS Code
  3. Two helper R packages (languageserver and httpgd) that make R feel at home in VS Code

Step 1: Install R

Windows

  1. Go to r-project.org.
  2. Click Download R, then Download R for Windows, then base.
  3. Click Download R X.X.X for Windows and run the installer. If Windows asks Do you want to allow this app to make changes to your device?, select Yes. If it asks for an administrator password instead, the person who manages that computer has to type it.
  4. Click through with the default location and components, then Finish.

Verify: open the R x64 app from the Start menu. You should get an R console with version information at the top.

Do not verify with R --version in PowerShell. The Windows installer does not add R to your command line, so that will say “not recognized” even when R is installed and working. Once you have installed Quarto, quarto check is the real answer to “is my setup working”.

macOS

  1. Go to r-project.org and click Download R for macOS.
  2. Download the right .pkg. Not sure which Mac you have? Apple menu, About This Mac: it lists the Chip (Apple M1, M2, and so on) or the Processor (Intel), and the macOS version.
    • Apple chip, macOS 14 (Sonoma) or newer: the arm64.pkg at the top of the page.
    • Apple chip, macOS 11 to 13: the newest arm64.pkg in the big-sur-arm64 folder. The arm64.pkg at the top of the page does not install on these versions.
    • Intel chip: the x86_64.pkg. It runs on an Apple chip too, but slowly, so do not pick it there.
  3. Run the installer and accept the defaults. If macOS asks whether the installer may use your Downloads folder, select Allow. If you selected Don’t Allow, the install fails: drag the .pkg from Downloads into your home folder (in Finder, Go, then Home) and open it from there.

Verify: open Terminal and type R --version. You should see version information.

Unlike Windows, this works on a Mac: the macOS installer does put R on your command line.

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install r-base

Verify: type R --version in Terminal.


Step 2: Install the R extension in VS Code

  1. Open VS Code and open the Extensions view (Ctrl/Cmd+Shift+X).
  2. Search for R by REditorSupport and click Install. With R 4.6 or newer it must be version 3.0.0 or newer, because earlier versions never connect to R 4.6.
  3. If you cloned the course workspace, this extension is already in the recommended list, so the workspace will prompt you to install it.

Optional: install the AURA Lab R Companion the same way (Extensions view, search AURA Lab R Companion, Install). Its Check my setup command finds R even on Windows, where R is not on your command line.


Step 3: Install the helper packages

The R extension talks to R through two small packages. With the AURA Lab R Companion, run AURA: Check my setup from the Command Palette and choose your course: its Install what is missing installs both. Without it, open a terminal in VS Code (Terminal, New Terminal), type R to start an R session, and run:

install.packages("languageserver", repos = "https://cloud.r-project.org")  # code completion, diagnostics, help
install.packages("httpgd", repos = "https://cloud.r-project.org")           # plots render in a VS Code panel

Type q() and then n to leave the R session when they finish.


Step 4: Install the course packages

With the AURA Lab R Companion, run AURA: Check my setup from the Command Palette and choose your course: it installs any course package that is missing and confirms that each one loads.

Without it, start R again (R in the terminal) and install the analysis packages, one at a time:

install.packages("tidyverse", repos = "https://cloud.r-project.org")   # ggplot2, dplyr, readr, tidyr, and more
install.packages("janitor", repos = "https://cloud.r-project.org")     # clean_names(), used from the first wrangling practice on
install.packages("likert", repos = "https://cloud.r-project.org")      # Likert-scale survey analysis
install.packages("rmarkdown", repos = "https://cloud.r-project.org")   # reports from your analysis
install.packages("effectsize", repos = "https://cloud.r-project.org")  # effect sizes in the tests (all courses)

MC 501 needs two more, which the Companion’s Install what is missing also installs, plus qrcode for the poster’s QR code (guide 18); car and ggstatsplot are optional extras:

install.packages("lm.beta", repos = "https://cloud.r-project.org")      # standardized slope in the regression (required in MC 501)
install.packages("pwr", repos = "https://cloud.r-project.org")          # power analysis for your sample size (required in MC 501)
install.packages("qrcode", repos = "https://cloud.r-project.org")       # the QR code on your conference poster (MC 501)
install.packages("car", repos = "https://cloud.r-project.org")          # post-hoc tests and diagnostics (optional)
install.packages("ggstatsplot", repos = "https://cloud.r-project.org")  # statistical plots with test results (optional)

Wait for each to finish (you’ll see a blank > prompt when done).


Step 5: Run your first R code in VS Code

ImportantWhen VS Code asks to install “sess”, click Install

The first time R opens in VS Code, a notice appears in the bottom-right corner: vscode-R needs bundled sess to attach the session watcher. Click Install bundled sess and wait about a minute. You must say yes: if you click Not now or Don’t ask again, R will not connect to VS Code, and the bottom bar keeps saying R: (not attached).

Missed it? Click the bell icon in the bottom-right corner of VS Code to find the notice again. If it is not there and you have the AURA Lab R Companion, run AURA: Fix R (not attached) from the Command Palette: it closes your R terminals, installs sess and the packages it needs, and opens a new R terminal. Without the Companion, close VS Code, open R itself (from the Start menu on Windows, or Applications on a Mac), and run these three lines one at a time:

install.packages(c("processx", "later", "jsonlite", "rstudioapi"), repos = "https://cloud.r-project.org")
p <- tail(Sys.glob(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode", "extensions", "reditorsupport.r-3*", "dist", "resources", "sess")), 1)
install.packages(p, repos = NULL, type = "source")

Then open VS Code again and start R. The bottom bar should show your R version.

  1. In your workspace, create a new file called hello.R.
  2. Type:
print("Hello, Communication Liaison!")
  1. With your cursor on that line, press Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac). VS Code starts an R terminal and runs the line.
  2. You should see:
[1] "Hello, Communication Liaison!"

If you see that output, you’re ready to go.


Step 6: Test your setup with data

In the same hello.R, add and run:

library(tidyverse)
data(mtcars)
head(mtcars)

You should see a table of car data, and a plot panel will open the first time you draw a chart. Your R setup is complete.


How R works in VS Code

Part of VS Code What it does for R
Editor Write .R and .qmd files; send lines to R with Ctrl/Cmd+Enter
R terminal The live R session where results appear; type commands directly here too
Workspace panel (R extension) Shows the variables and data you’ve loaded
Plots panel (httpgd) Where your charts render
Explorer Your project files; the open folder is your working directory, so no .Rproj is needed

You do not create a separate project file. In VS Code you simply open your workspace folder, and that folder is the working directory for the whole session.


Common first-time issues

“Command not found: R”

On Windows this is normal and not a problem. The installer deliberately leaves R off your command line. R still works, VS Code still finds it, and Quarto still finds it through the Windows registry. Use quarto check to confirm your setup rather than R --version.

On macOS or Linux, try restarting your computer, and if it persists use the full path /usr/local/bin/R.

The R extension cannot find R

Open Settings (Ctrl/Cmd+,), search for r.rpath, and set the path to your R executable (for example C:\Program Files\R\R-4.x.x\bin\R.exe on Windows, or /usr/local/bin/R on macOS).

“Could not find function”

Load the package first, for example library(ggplot2).

install.packages() seems stuck

Press Escape, then try a specific mirror:

install.packages("tidyverse", repos = "https://cloud.r-project.org")

Stray characters around every chunk, or two chunks running as one

Two symptoms, one cause. Either Run Cell puts odd characters before and after your code in the R console, something like [200~ and [201~ (on a Mac, 00~ and 01~), or the next chunk you run comes out joined onto the previous one and both execute together.

Fix it in your workspace:

  1. Open Settings. Ctrl and , on Windows, Cmd and , on a Mac.
  2. Click the Workspace tab along the top. This part matters: Workspace is the tab that holds the settings that came with your course folder.
  3. Search for bracketed.
  4. Untick R > Bracketed Paste.

Then give yourself a clean console, because R may be sitting part way through a command it never finished. Click the bin icon on the terminal panel to close the R terminal, then run a cell again and a new one opens.

Why this happens: bracketed paste is a feature for radian, an alternative R console that this course does not use. With plain R the markers it sends are not understood, so they arrive in your console as ordinary text wrapped around your code. That broken line leaves R waiting for the rest of a command that is never coming, which is why the chunk you run next gets added onto it instead of running on its own.

Whether you see visible characters or just odd behavior depends on your R build, which is why this looks random and affects some machines and not others.

Workspaces created from the course template before 2026-09-08 have this setting switched on. Copies made after that do not, so this only affects you if you set your workspace up earlier.

If you’re still stuck, reach out during office hours.


Next steps

  1. Installed R.
  2. Installed the R extension in VS Code.
  3. Installed the helper and course packages.
  4. Ran Check my setup (optional).
  5. Ran your first R code from the editor.
  6. Next: learn R basics in the R Workbook.

Resources

Questions? Check the troubleshooting section, search stackoverflow.com for your error, or visit office hours.