简体   繁体   English

如何在Azure笔记本中使用rmagic?

[英]How to use rmagic in Azure Notebooks?

I am trying to get some data out of R snippet to Azure Python 3 Jupyter notebook (hosting is available for free at http://notebooks.azure.com ). 我试图从R片段获取一些数据到Azure Python 3 Jupyter笔记本(托管可以在http://notebooks.azure.com免费获得)。

I tried the following in Python 3 notebook: 我在Python 3笔记本中尝试了以下内容:

%load_ext rmagic

then tried to embed R: 然后试图嵌入R:

%%R -o x
x <- 1

then 然后

x

Here I get Python error: name 'x' is not defined – see the picture below. 这里我得到Python错误: name 'x' is not defined - 请参见下图。 What is the right way to embed R into Python 3 and exchange data using Azure Notebooks? 将R嵌入Python 3并使用Azure笔记本交换数据的正确方法是什么?

Azure Notebooks http://nogin.info/R2Py.png Azure笔记本http://nogin.info/R2Py.png

@DmitryNogin, I reproduced the issue successfully. @DmitryNogin,我成功地转载了这个问题。 And according to the descprition below from here , you need to use %load_ext rpy2.ipython instead of %load_ext rmagic in jupyter notebook now. 并根据从下面的descprition 在这里 ,你需要使用%load_ext rpy2.ipython代替%load_ext rmagic现在jupyter笔记本。

The rmagic extension has been moved to rpy2 as rpy2.interactive.ipython. rmagic扩展已经作为rpy2.interactive.ipython移动到rpy2。

However, I got some other errors below when I tried %load_ext rpy2.ipython in notebook. 但是,当我在笔记本中尝试%load_ext rpy2.ipython时,我在下面遇到了一些其他错误。

ImportError: libRblas.so: cannot open shared object file: No such file or directory

I searched a solution which need to set an environment variable LD_LIBRARY_PATH with export LD_LIBRARY_PATH=/usr/lib64/MR0-3.3.0/R-3.3.0/lib/R/lib (the path value which I found via the command which R ) on Azure notebook server. 我搜索了一个需要设置环境变量LD_LIBRARY_PATH的解决方案,其中包含export LD_LIBRARY_PATH=/usr/lib64/MR0-3.3.0/R-3.3.0/lib/R/lib (我通过命令which R找到的路径值) )在Azure笔记本服务器上。 However, the host Ubuntu OS not be installed vi or vim and I don't know the sudo password for nbuser in the terminal, so although the solution works for ipython in the terminal of notebook server, it can't make the jupyter works. 但是,主机Ubuntu OS没有安装vivim ,我不知道终端中nbusersudo密码,所以虽然解决方案适用于笔记本服务器终端中的ipython,但它无法使jupyter工作。

My final work solution is that using the terminal of notebook server to command ln -s /usr/lib64/MR0-3.3.0/R-3.3.0/lib/R/lib/* ~/anaconda3_410/lib/ . 我的最终解决方案是使用笔记本服务器的终端来命令ln -s /usr/lib64/MR0-3.3.0/R-3.3.0/lib/R/lib/* ~/anaconda3_410/lib/

Then, when you enter %load_ext rpy2.ipython , you will get an error ImportError ..../libreadline.so.6: undefined symbol: PC . 然后,当您输入%load_ext rpy2.ipython ,您将收到错误ImportError ..../libreadline.so.6: undefined symbol: PC You only need to enter import readline to solve it before %load_ext rpy2.ipython . 您只需要在%load_ext rpy2.ipython之前输入import readline来解决它。

Finally, you can load rpy2.ipython for %R xxx with some warning information. 最后,您可以使用一些警告信息为%R xxx加载rpy2.ipython

在此输入图像描述

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM