Ipython notebook crash using rmagic extension

2020-07-24 16:00发布

问题:

I am trying to run the rmagic functions extension example, but ipython crashes with console error message '\u used without hex digits in character string starting "c:\u". I suspect that this is an R error message caused by rmagic passing c:\path instead of c:\ or c:/.

There is probably an easy way to fix this (IPython or Notebook startup parameters?) , but, as a newbie to rmagic and rpy2, I need some expert help please.

The following simple snippet from the example causes the kernel to die:

import rpy2
%load_ext rmagic
%R x=1 

I am a windows user...

回答1:

Found a solution to this ipython/windows problem here



回答2:

I am a Windows user. 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, type="cairo")' % (tmpd.replace('\\', '/'), png_args))

The reason you do this is described here and here



标签: ipython rpy2