Skip to content
Brian M. Schilder edited this page Nov 15, 2023 · 1 revision

VSCode is an IDE that support a ton of different languages (including R and Python). You can download it here.

Once it's installed, follow these steps.

VSCode + R tutorial

First, if you're going to use R in VSCode there's several tools that make your life much easier.

This tutorial gives a really nice walkthrough of how to set up VSCode with R.

However, it's missing a few pieces of information. 

So after going through the linked tutorial, read my notes below for clarification on those remaining points.

How to set up radian (in Terminal)

Install radian via pip

bash-3.2$ python3 -m pip install --user radian

Add python executables to your path

sudo nano /etc/paths

(Add the following line to the /etc/paths file):

/Users/<username>/Library/Python/3.8/bin

Alternatively, you could install radian via conda.

Install radian via conda

You can also install radian into a specific conda env (as opposed to your whole OS).

Here's some very useful tips on how to use R successfully in conda envs.

bash-3.2$ conda create  -n my_env r-essentials r-base 
bash-3.2$ conda source my_env
bash-3.2$ pip install -U radian

How to modify VSCode settings.json

Find paths to radian and r

bash-3.2$ which r
/usr/local/bin/r

bash-3.2$ which radian
/Users/schilder/Library/Python/3.8/bin/radian

Add paths to VSCode settings.json

In VSCode menu bar, go to File -> Preferences -> Settings, or simply use the key command: CMD,

I've indicated here where exactly you should enter which path.

{
    "editor.renderControlCharacters": true,
    "r.bracketedPaste": true,
    //"r.rterm.windows": "/Users/schilder/Library/Python/3.8/bin/radian", //Use this only for Windows 
    //"r.rterm.linux": "/Users/schilder/Library/Python/3.8/bin/radian", //Use this only for Linux
    "r.rterm.mac": "/Users/schilder/Library/Python/3.8/bin/radian", // Use this only for a Mac. ** RADIAN path goes here ** 
    "r.lsp.path": "/usr/local/bin/r", // ** R path goes here **
    "r.lsp.debug": true,
    "r.lsp.diagnostics": true,
    "r.rterm.option": [
        "--no-save",
        "--no-restore",
        "--r-binary=/usr/local/bin/r" // ** R path goes here **
    ],
}   

Notes:

radian will automatically enable multiline coding when you use curly brackets, e.g.:

my_func <- function(x){
    
}

Setting up Live Share

Install the Live Share Extension Pack here.

First, register your Live Share account via one of the options that it gives you in VSCode. GitHub is an easy option that just requires authorising 3rd party access with a single button push.

You can then connect to Live Share by clicking the "Live Share" button on the  lefthand side of the bottom bar in VSCode.

Using Live Share on HPC

If you have HPC mounted to your computer you can just open the project  folder ( CMD+O  ) and interact with it like you would any local project. The downsides are that it'll be slower to read/write files, and that you won't have access to the computing resources on HPC (to get around these two issues, I think we would have to request HPC to support  VSCode).

Clone this wiki locally