Running R in VS code

Visual Studio code is a free and open-source code editor developed by Microsoft. It is available for Windows, macOS, and Linux. It has become one of the most popular code editors among web developers, in my case I'm spending most of the time between this IDE, and the Copilot CLI.

VS code has extensions for many languages, and I've been using it for Angular, C#, SQL Server for years. and most recently I'm using

Installing R

Installing R in a Windows machine

The cleanest way to install R in a Windows machine is to do it throug the Windows Package Manager (winget). You can also install R through the official R project website.

winget install RProject.R --version 4.5.2

Installing the R language server

The R language server is the component that gives Visual Studio Code “RStudio‑like intelligence”: autocomplete, function hints, code navigation, etc.

install.packages("languageserver")
installed.packages()[, c("Package", "Version")]

Install the R VS Code extension

If you search for R extensions in Visual Studio Code you'll find a few options, we will go with the one recommended in the Visual Studio Code website.

  • Name: R
  • Publisher: REditorSupport
Run a simple file

Test with a simple file to verify we have everything setup correctly.

Creates a file named test.r and paste the following lines of code. Then open an R terminal within visuasl studio and place the cursor anywhere in the test.r file we created, now press CTRL + SHIFT + S to run the code in the terminal.
x <- 1:10
plot(x)

At this point you should have everything set and running!