Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jupyter R kernel with visual studio code

Tags:

For python jupyter notebooks I am currently using VSCode python extension. However I cannot find any way to use alternative kernels. I am interested in jupyter R kernel in particular.

Is there any way to work with jupyter notebooks using R kernel in VSCode?

like image 375
Salvatore Cosseddu Avatar asked Jun 07 '19 15:06

Salvatore Cosseddu


People also ask

How do you run an R in Jupyter Notebook in Visual Studio code?

To see if R installed correctly, open a new notebook in VS Code (open the Command Palette with Cmd-Shift-P, or by clicking on the wheel in the bottom left and selecting Command Palette, then type Jupyter Create New Notebook ). If you don't see a button for R , make sure you followed all the steps above!

How do I run an R file in VS Code?

If you want to run an entire R file, open the file in the editor, and press Ctrl+Shift+S and the file will be sourced in the active R terminal.

Can I use Jupyter Notebook with Visual Studio?

Notebooks in Visual Studio CodeCombined with the Jupyter extension, it offers a full environment for Jupyter development that can be enhanced with additional language extensions. If you want a best-in-class, free Jupyter experience with the ability to leverage your compute of choice, this is a great option.


1 Answers

Yes, it is possible. However, it's not recommended anymore, because it has some bugs. You should use the notebook in VSCode Insiders instead of it in VSCode, since there is support for notebooks of many languages natively.


Anyways, if you want to continue in VSCode, just have to install IRkernel (R kernel) first. According to the docs, run both lines to perform installation:

install.packages('IRkernel')
IRkernel::installspec()  # to register the kernel in the current R installation

Now, you should restart your VSCode and:

  • Type Ctrl + Shift + P to search for "Jupyter: Create New Blank Notebook" enter image description here

  • Click on the button right below ellipsis in upper right corner to choose kernel

    enter image description here

  • Switch to the desired kernel, in this case R's enter image description here

That's it!

like image 154
testing_22 Avatar answered Sep 20 '22 19:09

testing_22