fixed Rmagic in IPython Notebook

336 views
Skip to first unread message

erin clausing

unread,
Jun 19, 2013, 12:10:27 AM6/19/13
to pyth...@googlegroups.com

I finally got Rmagic to work.  One might be able to skip to step 5 if you have rpy2 working in Ipython but are still having problems with Rmagic.  It appears to be working correctly although the cell showing the [correct] results of the %R cell is unusually large for some reason.  Haven't tracked down why yet.  If you have any ideas, please let me know.

 

1.  I installed Python(x,y)-2.7.5.0.exe

2.  I had already installed R-2.15.3-win.exe

3.  I installed Rtools.  Exact filename: Rtools30.exe

4.  I installed rpy2-2.3.0dev.win32-py2.7.exe which I got from

 

 https://bitbucket.org/breisfeld/rpy2_w32_fix/issue/1/binary-installer-for-win32

 

following the instructions here for setting up Rhome, Ruser, and path variable changes

https://bitbucket.org/breisfeld/rpy2_w32_fix/src/fb33bd712535164c0661d7b19caf487c19a43c05/INSTALL_WINDOWS?at=default

 

I tried the regular non dev version of rpy2 but it didn't work for me.

 

5. Then I went to my IPython extention folder which for me is:  C:\Python27\Lib\site-packages\IPython\extensions

and opened rmagic.py for editing.  Found the line

 

self.r('png("%s/Rplots%%03d.png",%s)' % (tmpd, png_args))

 

and replaced it with the line:

 

self.r('png("%s/Rplots%%03d.png",%s)' % (tmpd.replace('\\', '/'), png_args))

 

The reason you do this is described here:

 

https://github.com/ipython/ipython/issues/2533

 

Supposedly this issue was fixed.  See here:

 

https://github.com/ipython/ipython/commit/13bc13ee3fdd28efb76a9cdb91789cd2a9c9fe9f

 

So I'm not quite sure why my Rmagic.py still had the problem.

 

 

6.  Put %load_ext rmagic in first cell and run it before trying %R

 

 

Hope this helps someone,

 

Erin

Joris Van den Bossche

unread,
Jun 20, 2013, 7:32:24 AM6/20/13
to pyth...@googlegroups.com
Has it something to do with following issues?

Blank figure appears in output:
Another issues that I experience on Windows:

And for those who don't want to build RPy2 yourself, Christophe Gohlke also provides binaries: http://www.lfd.uci.edu/~gohlke/pythonlibs/ (which worked for me).

Regards,
Joris


Op woensdag 19 juni 2013 06:10:27 UTC+2 schreef erin clausing het volgende:

erin clausing

unread,
Jun 20, 2013, 4:07:14 PM6/20/13
to pyth...@googlegroups.com
Thank you SO MUCH!!!!  I have spent way too many hours trying to fix this problem so I was just going to live with manually resizing the empty image to a tiny size for a while.

Going into rmagc.py and using your line fixed my problem:

self.r('png("%s/Rplots%%03d.png",%s, type="cairo")' % (tmpd.replace('\\', '/'), png_args))

If I use the %R as in the following example, I get output:

In [1]:
%load_ext rmagic
%R x=c(1,2,3)

Out[1]:
array([ 1.,  2.,  3.])

If I use the %%R, I get no output (I do get the output in the console) :
In [2]:
%%R
x <- c(0,1,2,3,4)
y <- c(1,1,1,1,1)
z = x + y
print(z)

However I can get the output using a %R in the next cell
In [3]:
%R z

Out[3]:
array([ 1.,  2.,  3.,  4.,  5.])

I can also do this to get the output:

In [4]:
%Rpull z
print(z)

[ 1.  2.  3.  4.  5.]

This link seems to imply that a block of R code won't bring anything back by default:
http://ipython.org/ipython-doc/dev/config/extensions/rmagic.html

Thanks again,
Erin
Reply all
Reply to author
Forward
0 new messages