'Using jupyter R kernel with visual studio code

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?



Solution 1:[1]

Yes, it is possible. It just requires an additional configuration to connect with the R kernel in VSCode.

It's worth noting that, if you prefer, you can use the notebook in VSCode Insiders where there is native support for notebooks in many languages, including R.


If you're using Jupyter in VSCode, firstly install IRkernel (R kernel).

According to the docs, run both lines to perform the installation:

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

Now, you should:

  1. Reload Window Ctrl + R

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

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

    enter image description here

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

That's it!

Solution 2:[2]

Agreed with @essicolo, if you are 100% stuck on using vscode this is a no-go.

[About kernels] Sorry, but as of right now this feature is only supported with Python. We are looking at supporting other languages in the future.

Yeah, that's the case for now, even if you start an external server. I hate having to say that, as we really want to support more of the various language kernels. But we started out with a Python focus and we still are pretty locked into that for the near future. Polyglot support is coming, but it won't be right away

per Microsoft Employee IanMatthewHuff

https://github.com/microsoft/vscode-python/issues/5109#issuecomment-480097310


preface - based on the phrasing of your question, I am making the assumption that you are trying to perform IRkernel in-line execution from your text ide without having to use a jupyter notebook / jupyterlab.

That said, if you're willing to go to the dark side, there might be some alternatives:

  1. nteract's Hydrogen kernel for Atom IDE - the only text ide that I'm aware of that still supports execution against IRkernel. I know, I know - it's not vscode but it's as close as you'll probably get for now.

enter image description here

  1. TwoSigma's Beaker notebook - it's been a lonngggg time for me but this a branch of jupyter that used to support polyglot editing, I'm not sure if that's still supported and it seems like you aren't that interested in notebooks anyway.

Solution 3:[3]

@testing_22 it works with me too

just add some note from my experience

It will failed If you run IRkernel::installspec() from RStudio or from Jupyter Conda environment failed wayenter image description here

Please run this syntax with VSCode terminal

install.packages('IRkernel')
IRkernel::installspec()

enter image description here

The rest is same, please restart VSCode and select "R" kernel from VSCode

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Community
Solution 3 Ichsan