Using Jupyter R Kernel with Visual Studio Code

How to use different versions of R kernels in VS code Jupyter notebooks when using Linux

You can add any number of custom kernels to the folder ~/.local/share/jupyter/kernels

If you already have one R kernel installed and working, there should be an 'r' folder already in this directory containing a kernel.json file with the following content:

{"argv": ["/usr/lib/R/bin/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
"display_name":"R",
"language":"R"
}

This allows this kernel to be available through the top right kernel options in VS code and you can add more by adding new folders to this directory (one per new kernel) with a corresponding kernel.json file inside. See more about adding kernels here. For example creating a new 'r3.6.3' folder with a new kernel.json containing:

{"argv": [".renv/versions/3.6.3/bin/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
"display_name":"R 3.6.3",
"language":"R"
}

will add this version of the kernel to the options available. Notice that you only need to specify the path location of the kernel version wherever you have it installed.

Also notice I'm using the library renv to manage various versions of R. If you don't want to create various folders for different kernels each time, you can combine renv to handle multiple versions of R and make sure the file does not point to any particular version but simply invokes R,

{"argv": ["R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
"display_name":"R renv",
"language":"R"
}

which will trigger VS code to use whatever version of R you are using at that moment via renv. See here for more on the latter library

Failed to start the Kernel - Jupyter in VS Code

Could you try to reinstall the pyzmq module?

pip uninstall pyzmq
pip install pyzmq==19.0.2

Integrating Python and Jupyter Notebook with Visual Studio Code

I discovered a very simple answer: I installed the VSC package in the official Snap repo.

VSC and Python-Jupyter look to be all playing nice together now:

Sample Image

jupyter server : not started, no kernel in vs code

I had exactly the same problem when I installed Visual Studio Code and tried to run some Python code from a jupyter notebook on my fresh Ubuntu 18.04.

How I solved it:

1) Press Command+Shift+P to open a new command pallete

2) Type >Python: Select Intepreter to start jupyter notebook server

3) Open the notebook again

And it worked fine. Hope it works for you.



Related Topics



Leave a reply



Submit