VS Code and R

RStudio

RStudio1 is (most likely, are there any numbers out there?) the most widespread IDE for R. However, getting more and more submerged into the R shiny world there was always a bit of a hassle toying around with R, HTML, CSS and Javascript.

I was using VisualStudio Code for my blog and Jupyter notebooks and recently saw a tweet from Miles McBain explaining how he integrated RStudio Addins in VSCode. This sparked my interest in completely ditching RStudio for my workflow and use VSCode as a single IDE for everything.

Why would I use VSCode?

  1. VSCode supports basically every programming languages.
  2. Like R itself, it comes with a vast package library supporting most features you could possibly want
  3. It is a smaller footprint in your system and feels a hinch more agile than RStudio - developing a shiny app and firing runApp() feels like a breeze
  4. Live share. A dead simple way to collaboratively work on projects. It automagically lets you do real-time pair programming and even share your console and localhost.

Setup

Minimal setup

The minimal software you need to work with R in VSCode is:

  1. Plain obviously, VSCode.
  2. VSCode R Extension + languageserver by Yuki Ueda.
    • Brings all the R magic into play. Interactive help for R functions, run selected lines, Syntax highlighting, dataframe and environment viewer, shortcuts for basically everything one needs.

Installation guides can be found here:

My setup

Since I occasionally also work with a couple of other programming languages I installed a plethora of packages to support them. Furthermore - I really like the look and feel of the themes that the community of VSCode provides. Currently, I am really into Synthwave ‘84.

My complete setup:

If you want to have a quick start, just install the Settings Sync package in VSCode and enable downloading settings from a public Gist (see Details here).

Things that are missing

  • Autocompletion for columns/variables in dataframes/lists etc.
    • Turns out … this is possible! Just turn on r.sessionWatcher in your VSCode settings and enjoy!
  • On Mac, since you have to open Quartz for plotting, the plotting process seems to be quite slow. There may be something I am not familiar with that fixes this, but haven’t found a solution so far.

Conclusion

VSCode feels a bit like an IDE on Steroid, if you are only used to RStudio. Both in capabilities, as in speed. I really like working with it, since I rarely use the things I noticed that are missing in comparison to RStudio.