34

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?

Salvatore Cosseddu
  • 472
  • 1
  • 4
  • 11
  • 4
    Folks at Microsoft are on it. https://github.com/Microsoft/vscode-python/issues/5078#issuecomment-608175269 – essicolo Apr 07 '20 at 13:55
  • As of 2023, R Kernel for Jupyter Notebooks is supported in VS Code (reference to [Jupyter Extension for VS Code](https://github.com/microsoft/vscode-jupyter/blob/113c3e54ac1d3cb81ab6473d1a5fa4a20cce4755/README.md#working-with-other-languages)). – ands Feb 09 '23 at 15:21

3 Answers3

14

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!

testing_22
  • 2,340
  • 1
  • 12
  • 28
  • 7
    could you provide some info or link why is buggy about vs code and the integration with R kernel ? Maybe just not the case anymore ? Looks to me it works pretty well – JRodrigoF Aug 24 '21 at 10:18
  • Just in case that someone has the same trouble as me following the instructions without getting it to work: it might be necessary to call `IRkernel::installspec(user = FALSE)` , for me it did not show up in the list of kernels before. – Nayangar Jul 11 '22 at 13:04
  • 1
    Does this still work? – catastrophic-failure Sep 01 '22 at 09:47
  • It still works in 2023 on vscode 1.81 – hyena Aug 07 '23 at 21:42
1

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.
Community
  • 1
  • 1
sgdata
  • 2,543
  • 1
  • 19
  • 44
0

@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

Ichsan
  • 768
  • 8
  • 12