How to use rmagic in Azure Notebooks?
<p>I am trying to get some data out of R snippet to Azure Python 3 Jupyter notebook (hosting is available for free at <a href="http://notebooks.azure.com" rel="nofollow">http://notebooks.azure.com</a>).</p>

<p>I tried the following in Python 3 notebook:</p>

<pre><code>%load_ext rmagic
</code></pre>

<p>then tried to embed R: </p>

<pre><code>%%R -o x
x &lt;- 1
</code></pre>

<p>then</p>

<pre><code>x
</code></pre>

<p>Here I get Python error: <code>name 'x' is not defined</code> â see the picture below. What is the right way to embed R into Python 3 and exchange data using Azure Notebooks?</p>

<p><img src="http://nogin.info/R2Py.png" alt="Azure Notebooks"></p>

<p>@DmitryNogin, I reproduced the issue successfully. And according to the descprition below from <a href="https://ipython.org/ipython-doc/2/config/extensions/rmagic.html" rel="nofollow">here</a>, you need to use <code>%load_ext rpy2.ipython</code> instead of <code>%load_ext rmagic</code> in jupyter notebook now.</p>

<blockquote>
  <p>The rmagic extension has been moved to rpy2 as rpy2.interactive.ipython.</p>
</blockquote>

<p>However, I got some other errors below when I tried <code>%load_ext rpy2.ipython</code> in notebook.</p>

<pre><code>ImportError: libRblas.so: cannot open shared object file: No such file or directory
</code></pre>

<p>I searched a solution which need to set an environment variable <code>LD_LIBRARY_PATH</code> with <code>export LD_LIBRARY_PATH=/usr/lib64/MR0-3.3.0/R-3.3.0/lib/R/lib</code> (the path value which I found via the command <code>which R</code>) on Azure notebook server. However, the host Ubuntu OS not be installed <code>vi</code> or <code>vim</code> and I don't know the <code>sudo</code> password for <code>nbuser</code> in the terminal, so although the solution works for ipython in the terminal of notebook server, it can't make the jupyter works.</p>

<p>My final work solution is that using the terminal of notebook server to command <code>ln -s /usr/lib64/MR0-3.3.0/R-3.3.0/lib/R/lib/* ~/anaconda3_410/lib/</code>. </p>

<p>Then, when you enter <code>%load_ext rpy2.ipython</code>, you will get an error <code>ImportError ..../libreadline.so.6: undefined symbol: PC</code>. You only need to enter <code>import readline</code> to solve it before <code>%load_ext rpy2.ipython</code>.</p>

<p>Finally, you can load <code>rpy2.ipython</code> for <code>%R xxx</code> with some warning information.</p>

<p><a href="http://i.stack.imgur.com/fdhsm.png" rel="nofollow"><img src="http://i.stack.imgur.com/fdhsm.png" alt="enter image description here"></a></p>

<p>Hope it helps.</p>

python azure jupyter