VSCode set up for Bioinformatics

R, Python, Jupyter notebook

Ksenia Troshchenkova
3 min readApr 14, 2021
Image by author

Since the university I used Jupyter notebook for the data analysis both in R and Python. I like Jupyter notebooks for the ability to mix code, markdowns and visualization, so I can bring together the analysis, its description and caveats along with the results. In the kaggle survey you can explore which technologies were preferred by data scientists in 2020. Lately while using Jupyter notebook with R I lacked some functionality even after adding extensions. That led me to trying out the Jupyter notebook integration in VSCode.

What I found attractive in VSCode is possibility to integrate with many languages in one IDE. If you are planning to add another language to your palette — check the VSCode extensions, it is probably there already.

Even though the VSCode does not offer good integration of Jupyter notebook in R so far, this possibility is offered by the VSCode Insiders. VSCode insiders is a beta version of the VSCode with the latest bug fixes and features. It is updated daily and might not be stable. For this reason, the notebooks may stop working, but if any issues appear, they are usually quickly fixed. Alternatively, you can fix the extension by rolling back to the previous version, which worked for you.

In this tutorial we are going to set up the VSCode with R and Python integrated in the Jupyter notebook on Mac from scratch.

Install package management software

I use Homebrew since it is the most popular one for macOS and it is available on linux.

The commands for other package managers will be very similar. So, if you are using other package manager just follow the steps and do the same with the package manager you are using.

The following command will install Homebrew when pasted to the macOS terminal or to Linux shell promt.

$ /bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"

Install Python

The easiest way is to install it using the homebrew.

The following command will install Python3.

$ brew install python

Install R

The following command will install R4.0.4

$ brew install r

Install Jupyter

$ brew install jupyter

Prepare R for notebook experience

Firstly, launch R in terminal:

$ R

In the R console is launched run the following command to install IRkernel:

> install.packages('IRkernel')

Next, make the kernel visible for the Jupyter. To do so system-wide and not only for one user run:

> IRkernel::installspec(user = FALSE)

Next install language server package. This package will enable auto-complete, code formatting, information etc. for R. More info about this package you may find here.

> install.packages("languageserver")

Download VSCode Insiders

You can download the VSCode Insiders from here.

Install extensions

After downloading and installing the VSCode Insiders you will see the following screen.

Click on the icon with 4 squares on it (5th icon in activity panel on the left).

Type in the names of the following extensions and install them.

  • R
  • R LSP Client
  • Python
  • Jupyter

Create the Jupyter notebook

After this you should be able to create the Jupyter notebook.

  1. Create notebook:
  • cmd+shift+p
  • type in (you will get this in a drop down menu after you start typing): Jupyter: Create New Blank Notebook

2. Check which kernels are available (you will get a drop down menu with available kernels to choose):

  • cmd+shift+p
  • type in (you will get this in a drop down menu after you start typing): Notebook: Select Notebook Kernel

Time to run some code

Now you are all set up to start using Python or R with Jupyter notebook in VSCode.

Try to run the following command:

print("I am ready to go")

To switch between kernels simply click on the current kernel name in the bottom right corner. This will get you back to the drop down menu with available kernels.

Conclusion

We have now set up VSCode to use Jupyter notebooks with R and Python.

I hope you found this article useful!
Feel free to leave any questions in the comments below. I’ll be glad to help out!

--

--