9

Issue description

Whenever loading rpy2 in a Jupyter notebook, R code executed with a %%Rcell magic gets printed in the command prompt instead of the notebook cell. Plots show up properly in the notebook though.

enter image description here

I also noticed that the %R inline magic works properly, with code printed in the cell as expected.

Installation steps

  1. Python 2.7.11 :: Anaconda 2.5.0 (64-bit)
  2. notebook 4.1.0 installed via pip
  3. R 3.3.1 (x64) located in Program Files
  4. rpy2-2.7.8-cp27-none-win_amd64.whl installed via pip
  5. PATH:
    • R_USER = C:\Users\myusername
    • R_HOME = C:\Program Files\R\R-3.3.1
    • Added C:\Program Files\R\R-3.3.1\bin\i386
6
  • I don't know, seems to work fine for me on the mac. Can you show the exact commands you're using to activate the rmagic? Otherwise, might be a windows thing. Commented Jul 19, 2016 at 4:32
  • I call %load_ext rpy2.ipython and then add %%R at the top of the cell. Commented Jul 19, 2016 at 7:40
  • 1
    Yeah, that's what I did and it works for me. You could try submitting a bug report on rpy2's bitbucket site Commented Jul 19, 2016 at 22:54
  • Did you solve this? Commented Oct 5, 2017 at 15:12
  • Unfortunately, no... Commented Oct 5, 2017 at 17:12

1 Answer 1

2

You can use the RWinOut Jupyter extension. The following installation instructions are taken from the GitHub page:

You can run the following curl command from a Jupyter notebook cell to download the file to your working directory. You can also download it manually and put it there yourself.

!curl -O "https://raw.githubusercontent.com/vitorcurtis/RWinOut/master/RWinOut.py"

Once it's in your working directory, you can replace %load_ext rpy2.ipython at the top of your script with %load_ext RWinOut. Then you should be able to see the output of cells containing the %%R magic as normal.

This isn't a complete solution, but it's a workaround that might achieve the same effect. I'm not sure if this breaks some functionality, but it seems to work fine for me.

Tested with:

  • Windows 10 v.1809 Build 17763.503
  • Python 3.7.2
  • R 3.6.0
  • rpy2 2.9.5

One other option is to use the Windows Subsystem for Linux and launch your Jupyter notebook from there. This might not be desirable if you have to reinstall a lot of R and Python packages into a different environment, but will make it so the output will print correctly without requiring this hacky workaround.

Sign up to request clarification or add additional context in comments.

1 Comment

Running Linux in Windows might be long term solution. The dev version of rpy2 (future rpy2-3.1.0) has tentative initialization code for Windows but to my knowledge it was not tested by anyone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.