本文介绍了在安装了anaconda的新服务器上关闭ipython笔记本电脑运行时错误的R magic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢ipython笔记本中的R魔法。我不得不切换到新的服务器,并听说通过anaconda安装所有东西可以解决一个巨大的问题。但是,R magic似乎不起作用,这是我使用ipython笔记本的原因的一半。

I loved the R magic in ipython notebook. I had to switch to a new server and heard that a huge headache can be taken out by installing everything through anaconda. However, R magic doesn't seem to work, which is half the reason I use ipython notebook.

安装anaconda之后,我打开一个笔记本,只需键入以下内容即可。

After installing anaconda, I open a notebook and simply type the following.

%load_ext rmagic
%%R
print("hi")

这会产生运行时错误我无法到达底部:

This produces a Runtime error I can't get to the bottom of:

--------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
<ipython-input-6-89259627ca18> in <module>()
----> 1 get_ipython().run_cell_magic(u'R', u'', u'print("hi")')

/nas1/apps/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell)
   2160             magic_arg_s = self.var_expand(line, stack_depth)
   2161             with self.builtin_trap:
-> 2162                 result = fn(magic_arg_s, cell)
   2163             return result
   2164 

/nas1/apps/anaconda/lib/python2.7/site-packages/IPython/extensions/rmagic.pyc in R(self, line, cell, local_ns)

/nas1/apps/anaconda/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

/nas1/apps/anaconda/lib/python2.7/site-packages/IPython/extensions/rmagic.pyc in R(self, line, cell, local_ns)
    626             return
    627         finally:
--> 628             self.r('dev.off()')
    629 
    630         # read out all the saved .png files

/nas1/apps/anaconda/lib/python2.7/site-packages/rpy2/robjects/__init__.pyc in __call__(self, string)
    244     def __call__(self, string):
    245         p = rinterface.parse(string)
--> 246         res = self.eval(p)
    247         return res
    248 

/nas1/apps/anaconda/lib/python2.7/site-packages/rpy2/robjects/functions.pyc in __call__(self, *args, **kwargs)
    164                 v = kwargs.pop(k)
    165                 kwargs[r_k] = v
--> 166         return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
    167 
    168 pattern_link = re.compile(r'\\link\{(.+?)\}')

/nas1/apps/anaconda/lib/python2.7/site-packages/rpy2/robjects/functions.pyc in __call__(self, *args, **kwargs)
     97         for k, v in kwargs.items():
     98             new_kwargs[k] = conversion.py2ri(v)
---> 99         res = super(Function, self).__call__(*new_args, **new_kwargs)
    100         res = conversion.ri2ro(res)
    101         return res

RRuntimeError: Error in dev.off() : cannot shut down device 1 (the null device)

我重启服务器确保运行的唯一R实例就是这个。 Rpy2可以工作,因为我可以使用这个库打印出情节,但是R magic总是产生这个RunTimeError。

I restart my server to assure that the only R instance running is this one. Rpy2 works, as I can print out plots using this library, but the R magic always produces this RunTimeError.

任何帮助?

(我不确定我是否应该在SO或其他交易所发布,但根据我得到的答案,我会适应)

(I'm not sure if I should post this on SO or another exchange, but based on what answers I get, I will adapt)

推荐答案

我不确定这是否有所帮助,但似乎是不再使用%load_ext rmagic 了。您可能想尝试%load_ext rpy2.ipython

I'm not sure if this advice from another thread helps, but seems like newer versions of rpy2 do not use %load_ext rmagic anymore. You might want to try %load_ext rpy2.ipython.

这篇关于在安装了anaconda的新服务器上关闭ipython笔记本电脑运行时错误的R magic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 20:37