Swastik
Swastik

Reputation: 101

Installing R kernel for Ipython on Windows

I am on Windows 10. I have installed R-3.2.0, Anaconda 2.2.0 64 bit, RStudio-0.99.446. Also, edited system path variable to include R installation directory.

I am following all the instruction given in https://github.com/IRkernel/IRkernel but I am not getting R kernel when I open Ipython notebook.

Can anybody tell what am I missing?

Upvotes: 3

Views: 2489

Answers (3)

Ferd
Ferd

Reputation: 1341

Those who haven't installed it yet can follow these instructions:

Visit this LinkedIn post if you want to read the instructions in spanish.

1) Create your R virtual enviroment

Skip this step if you have it already. If you don't know how to create it, visit this page.

2) Get your R executable path

This step is to make sure you to use the proper instalation of R through the next steps and with that, avoid reference/path errors later. There are several ways to get the path, the one I propose is the following:

  • 2.1 Run Anaconda prompt as administrator. If you don't know how to do it visit this page.

  • 2.2 In Anaconda Prompt, active your R virtual enviroment using the command activate {my enviroment's name}(notice that, in my case, I named my R virtual enviroment as 'RStudio'):

enter image description here

  • 2.3 Run R: Just type R and press Enter.

enter image description here

  • 2.4 Run the following method to get the base path.

R.home()

enter image description here

  • 2.5 Navigate to the path you got in the previous step (you can use Windows Explorer for this), go to the bin folder and copy the path where R.exe is located. Notice: If your OS have a 64bit architecture, you should copy the path from the x64 folder.

In my case:

enter image description here

3) Quit R session, and then, deactivate your virtual enviroment

You can use the method q() to quit R. For deactivating your virtual enviroment use the command: conda deactivate

enter image description here

4) Run R from your base enviroment

Go to the path you copied in Step 2. For that, use the command:

cd {your path here}

Once there, type R.exe and press Enter.

e.g.

enter image description here

If you got no errors here, go to Step 5.

If you got a dynamic link library error like this when trying to run R.exe:

enter image description here

Use the following command:

conda install -c r r

enter image description here

Once solved, run R.exe again and then, continue to Step 5

5) Installing R kernel stuff

Now, you're in Anaconda Prompt as Administrator, with your R session opened from the base enviroment, the next you must do is:

  • 5.1 Install devtools. Just run the following method with "devtools" as parameter:

install.packages("devtools")

Now, your R kernel is set and ready to go!

enter image description here

Upvotes: 0

lgalarno
lgalarno

Reputation: 29

Once IRkernel is installed, you can also simply issue the following command in R:

IRkernel::installspec(user = FALSE)

The kernel.json file should be automatically created in the appropriate folder ("C:\ProgramData\jupyter\kernels\ir"), along with a nice R logo

Upvotes: 2

Swastik
Swastik

Reputation: 101

Got it working, after following all the process mentioned in IRkernel GitHub page. Create kernel.json file in C:\Users\[username]\.ipython\kernels\R_kernel, content of the file should be

{"argv": ["C:/Program Files/R/R-3.2.0/bin/R.exe","-e","IRkernel::main()",
"--args","{connection_file}"],
"display_name":"R"
}

Note that instead of forward slash path should contain backward slash as mentioned above.

Upvotes: 2

Related Questions