How to install and use R in VSCode
Last updated: February 3, 2023
Most of the R world uses RStudio, as the default IDE which I cannot stand. It’s ugly, slow and cumbersome.
RStudio is owned by CRAN (a package registry) and it also manages your installation of the R language itself. That makes troubleshooting hard. The default answer is often “Have you tried reinstalling R?”
This isn’t 2003, I prefer:
- Reproducible installation steps
- A modern coding editor (VSCode)
Here’s how to do that on macOS.
Use Homebrew on macOS and Linux to download and install the language. (Good luck Windows). You do not need to install RStudio.
brew install r
That will download R and install the correct version for your operating system (depending on whether it uses Intel, or Apple Silicon, etc). And it will install Python v3 too, because why not.
We have to install the VSCode Language server using R itself using
pkg, the R package manager.
Optional: First, install Radian, which is a pretty R console:
pip3 install -U radian
- Open a terminal
- Run R by typing
rto get into the console.
- Install the language server by typing this:
It’s going to take forever because it’s doing some C++ compiler stuff like it’s 1995 …
- Get out of this ugly console:
- Close your terminal
- Open VSCode.
- Install the R Extension for VSCode
- Add the following properties to your
"r.bracketedPaste": true, "r.rterm.mac": "/usr/local/bin/radian"
Create an R file, then write some R code in it.
Click on the “Run source” icon on the top right. It looks like a play button.
Watch it run on the terminal, you’re done!