'How to use jupyter notebook with R kernal in VS code?

Now I can use jupyter lab with R kernal in a web browser and use VS Code to edit jupyter note book code with python kernal, is it possible to edit R code in VS Code with jupyter notebook mode? Thanks for the comments and solutions.



Solution 1:[1]

Yes, it is possible. You just have to install IRkernel (R kernel) first.

According to the docs, run both lines

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

Then, 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!

Solution 2:[2]

@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 way

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 Ichsan