Whenever loading rpy2 in a Jupyter notebook, R code executed with a %%R
cell magic gets printed in the command prompt instead of the notebook cell. Plots show up properly in the notebook though.
I also noticed that the %R
inline magic works properly, with code printed in the cell as expected.
R_USER = C:\Users\myusername
R_HOME = C:\Program Files\R\R-3.3.1
C:\Program Files\R\R-3.3.1\bin\i386
It is your expection that needs to be adapted. The Jupyter Notebook only shows what the last statement of a cell evaluates to. If you define a function, this does not evaluate to anything that could be displayed. So you can't see anything in the upper cell.
Windows File Explorer + Command Prompt Once you've entered your specific folder with Windows Explorer, you can simply press ALT + D, type in cmd and press Enter. You can then type jupyter notebook to launch Jupyter Notebook within that specific folder.
Jupyter Notebook can print the output of each cell just below the cell. When you have a lot of output you can reduce the amount of space it takes up by clicking on the left side panel of the output. This will turn the output into a scrolling window.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With