I should say that what I really want to do is to take an .ipynb file and execute it in such a way that I can take some things from its namespace into<div>the namespace of the python process. For example, I might have a function or a class defined in the .ipynb file that I want to pull into the python process.</div>
<div><br></div><div>Using InteractiveShell or TerminalInteractiveShell seems to work for this, except for raising errors about not finding the %R magic.<br><br><div class="gmail_quote">On Thu, Jun 14, 2012 at 3:44 PM, Jonathan Taylor <span dir="ltr"><<a href="mailto:jonathan.taylor@stanford.edu" target="_blank">jonathan.taylor@stanford.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Actually, I want to create an InteractiveShell inside another python process. Maybe I should use embed?<div><br></div><div>
Inside ipython this doesn't work, but maybe it would inside another python process?</div><div><br>
</div><div><div>In [12]: import IPython.frontend.terminal as IT</div><div><br></div><div>In [13]: shell = IT.embed.InteractiveShellEmbed()</div><div><br></div><div>In [14]: shell.run_cell('%R X=rnorm(20)')</div><div class="im">
<div>
ERROR: Line magic function `%R` not found.</div><br></div><div><div class="h5"><div class="gmail_quote">On Thu, Jun 14, 2012 at 3:35 PM, MinRK <span dir="ltr"><<a href="mailto:benjaminrk@gmail.com" target="_blank">benjaminrk@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><br><div class="gmail_quote"><div>On Thu, Jun 14, 2012 at 3:23 PM, Jonathan Taylor <span dir="ltr"><<a href="mailto:jonathan.taylor@stanford.edu" target="_blank">jonathan.taylor@stanford.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I'm trying to run some cells through InteractiveShell and am getting an unexpected error message which is that my shell<div>can't find the %R line magic:</div><div><br></div><div><div><br></div><div>In [1]: import IPython.frontend.terminal.interactiveshell as IS</div>




<div><br></div><div>In [2]: shell = IS.InteractiveShell()</div><div><br></div><div>In [3]: shell.run_cell('%load_ext rmagic')</div><div><br></div><div>In [4]: shell.run_cell('%R X=rnorm(20)')</div><div>ERROR: Line magic function `%R` not found.</div>




<div>In [5]: </div><div><br></div><div>In [5]: load_ext rmagic</div><div><br></div><div>In [6]: %R X=rnorm(20)</div><div>Out[6]: </div><div>array([ 0.08724969,  2.03344439, -0.82111458, -2.07136391, -0.11913743,</div><div>




        0.19598438,  0.58574042, -0.33684877, -0.9659225 , -0.68404775,</div><div>       -0.0278716 ,  1.34169008, -0.6034878 ,  1.76146422, -0.19225874,</div><div>       -1.15088263, -1.10644146, -1.27298014, -1.18212805,  1.60194601])</div>




<div><br></div><div>Is this expected? I can't tell.</div></div></blockquote><div><br></div></div><div>One thing that's not at all expected is creating a new InteractiveShell inside an InteractiveShell.  Do you mean to be creating a whole new InteractiveShell object in which to run these commands?</div>



<div><br></div><div>If you want a handle on the*existing* shell, you can use: shell = get_ipython().</div><div><br></div><div>If you do that, your run_cell calls above seem to behave as you are expecting.</div><div> </div>



<div>-MinRK</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><span><font color="#888888"><div><br></div><div><br></div><div><div>


<br></div>-- <br>Jonathan Taylor                          <br>Dept. of Statistics                      <br>Sequoia Hall, 137                          <br>
390 Serra Mall<br>Stanford, CA 94305<br>Tel:   <a href="tel:650.723.9230" value="+16507239230" target="_blank">650.723.9230</a><br>Fax:   <a href="tel:650.725.8977" value="+16507258977" target="_blank">650.725.8977</a><br>



Web: <a href="http://www-stat.stanford.edu/~jtaylo" target="_blank">http://www-stat.stanford.edu/~jtaylo</a><br>
</div></font></span></div>
<br></div>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Jonathan Taylor                          <br>Dept. of Statistics                      <br>Sequoia Hall, 137                          <br>390 Serra Mall<br>

Stanford, CA 94305<br>Tel:   <a href="tel:650.723.9230" value="+16507239230" target="_blank">650.723.9230</a><br>Fax:   <a href="tel:650.725.8977" value="+16507258977" target="_blank">650.725.8977</a><br>Web: <a href="http://www-stat.stanford.edu/~jtaylo" target="_blank">http://www-stat.stanford.edu/~jtaylo</a><br>

</div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Jonathan Taylor                          <br>Dept. of Statistics                      <br>Sequoia Hall, 137                          <br>390 Serra Mall<br>Stanford, CA 94305<br>
Tel:   650.723.9230<br>Fax:   650.725.8977<br>Web: <a href="http://www-stat.stanford.edu/~jtaylo">http://www-stat.stanford.edu/~jtaylo</a><br>
</div>