Install R for VS Code

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.
  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: Apple Silicon (M1/M2/M3) uses the ARM64 build, Intel Macs use the Intel build. Not sure? Apple menu, About This Mac, check the chip.
  3. Run the installer and accept the defaults.

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.
  3. If you cloned the course workspace, this extension is already in the recommended list, so the workspace will prompt you to install it.

Step 3: Install the helper packages

The R extension talks to R through two small packages. Open a terminal in VS Code (Terminal, New Terminal), type R to start an R session, and run:

install.packages("languageserver")  # code completion, diagnostics, help
install.packages("httpgd")           # 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

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

install.packages("tidyverse")   # ggplot2, dplyr, readr, tidyr, and more
install.packages("likert")      # Likert-scale survey analysis
install.packages("rmarkdown")   # reports from your analysis

For later phases you may also want:

install.packages("lm.beta")      # standardized regression coefficients
install.packages("car")          # post-hoc tests and diagnostics
install.packages("ggstatsplot")  # statistical plots with test results

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


Step 5: Run your first R code in VS Code

  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~, 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 your first R code from the editor.
  5. Next: learn R basics in the R Workbook.

Resources

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