rjupyter-notebookubuntu-18.04jupyter-irkernel

How to upgrade IRKernel in Ubuntu?


On Ubuntu 18.04 LTS, while working R in JupyterNotebook (without Anaconda), the IRKernel is reading the R version 3.4. For using some packages like cowplot it is necessary to have at least version 3.5.


Solution

  • Basically, two steps should be taken:

    1. Update R. These and that answers were a guideline.
    2. Update IRKernel. The offical IRKernel instructions for Linux were useful.

    Next, is described the complete procedure

    1. Add Key to server

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
    

    2. Add Entry to sources.list

    echo 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/' | sudo tee -a /etc/apt/sources.list
    

    Depending on the linux you're using you should change, for example, bionic by xenial or cosmic, check out https://cran.r-project.org/bin/linux/ubuntu/README.html

    3. Update Programs

    According to the instructions in the above link, we should do the following:

    sudo apt-get update
    sudo apt-get install r-base
    sudo apt-get install r-base-dev
    

    4. Update /.local/share/jupyter/kernels/ir

    type R in the console and follow the next steps according to this link

    # In the console
    R
    # Inside R
    install.packages(c('repr', 'IRdisplay', 'IRkernel'), type = 'source')
    getRversion() # to verify the new R version
    IRKernel::installspec()
    

    This should show the following message:

    [InstallKernelSpec] Removing existing kernelspec in /home/user_name/.local/share/jupyter/kernels/ir
    [InstallKernelSpec] Installed kernelspec ir in /home/user_name/.local/share/jupyter/kernels/ir
    

    As a final remark, you should remove the older version of R, which you can find in ~/R/x86_64-pc-linux-gnu-library, where you will now have two directories with two different versions or R (remove the older one).