frogfanitw
frogfanitw

Reputation: 175

Using a new windows version of R in Jupyter notebooks

I've installed R version 3.5.1 for windows and copied its contents to the R folder used by Anaconda3. However conda still identifies the current version as 3.4.3. Is there a "version id" file somewhere in the Anaconda3 folders?

Upvotes: 3

Views: 4476

Answers (1)

Short solution

In short you need to install a the IRkernel package in the version of R you want to use with Jupyter and then make it available to Jupyter. See here.

Diagnosis

You may not be aware that you have two installations of R. To confirm this is the case in a Jupyter Notebook, type:

R.version

This should return values such as:

               _  
platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          4.3                         
year           2017                        
month          11                          
day            30                          
svn rev        73796                       
language       R                           
version.string R version 3.4.3 (2017-11-30)
nickname       Kite-Eating Tree       

Now open RStudio or RGui and input the same command, you should see different output (ignore any warnings):

               _                           
platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          5.0                         
year           2018                        
month          04                          
day            23                          
svn rev        74626                       
language       R                           
version.string R version 3.5.0 (2018-04-23)
nickname       Joy in Playing   

Note the differences in the version.string and nickname variables in particular.

Now in your Jupyter notebook type:

R.home()

Which will give the output like:

"C:/Anaconda3/lib/R"

The same command in RStudio or RGui will return a different path e.g.:

"C:/R/R-35~1.0"

The above values may not match those on your machine, but if they are different to each other the following steps will allow you to use the latest R instance from Jupyter.

Longer solution

  1. Copy the above R.home() path from Rstudio (or RGui)
  2. Open Anaconda Prompt form the start menu
  3. Type cd /d "C:/R/R-35~1.0" where the path is the same as the one you have copied. Hit return.
  4. Type cd bin. Hit return
  5. Type R.exe to launch the command line R from that directory
  6. We now need to install the package IRkernel. This package makes the version of R callable as an Jupyter kernel. Type install.packages('IRkernel') and hit return.
  7. Type IRkernel::installspec(name = 'ir35', displayname = 'R 3.5.0') to create the latest R kernel. Note you can change the name and display name to be whatever you wish.
  8. Exit R and close any instances of Jupyter Notebooks you have running.
  9. Launch Jupyter Notebook again and click to create a new notebook. You should find your kernel available by its display name in the drop down box.

Upvotes: 6

Related Questions