Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do you mean something like this?</p> <pre><code>export NUM=10 R -q -e "rnorm($NUM)" </code></pre> <p>You might also like to check out <code>littler</code> - <a href="http://dirk.eddelbuettel.com/code/littler.html">http://dirk.eddelbuettel.com/code/littler.html</a></p> <p><strong>UPDATED</strong></p> <p>Following your comment below, I think I am beginning to understand your question better. You are asking about running python inside the R shell.</p> <p>So here's an example:-</p> <pre><code># code in a file named myfirstpythonfile.py a = 1 b = 19 c = 3 mylist = [a, b, c] for item in mylist: print item </code></pre> <p>In your R shell, therefore, do this:</p> <pre><code>&gt; system('python myfirstpythonfile.py') 1 19 3 </code></pre> <p>Essentially, you can simply call <code>python /path/to/your/python/file.py</code> to execute a block of python code.</p> <p>In my case, I can simply call <code>python myfirstpythonfile.py</code> assuming that I launched my R shell in the same directory (path) my python file resides.</p> <p><strong>FURTHER UPDATED</strong></p> <p>And if you <em>really</em> want to print out the source code, here's a brute force method that might be possible. In your R shell:-</p> <pre><code>&gt; system('python -c "import sys; sys.stdout.write(file(\'myfirstpythonfile.py\', \'r\').read());"; python myfirstpythonfile.py') a = 1 b = 19 c = 3 mylist = [a, b, c] for item in mylist: print item 1 19 3 </code></pre> <p><strong>AND FURTHER FURTHER UPDATED :-)</strong></p> <p>So if the purpose is to print the python code before the execution of a code, we can use the python trace module (reference: <a href="http://docs.python.org/library/trace.html">http://docs.python.org/library/trace.html</a>). In command line, we use the <code>-m</code> option to call a python module and we specify the options for that python module following it.</p> <p>So for my example above, it would be:-</p> <pre><code>$ python -m trace --trace myfirstpythonfile.py --- modulename: myfirstpythonfile, funcname: &lt;module&gt; myfirstpythonfile.py(1): a = 1 myfirstpythonfile.py(2): b = 19 myfirstpythonfile.py(3): c = 3 myfirstpythonfile.py(4): mylist = [a, b, c] myfirstpythonfile.py(5): for item in mylist: myfirstpythonfile.py(6): print item 1 myfirstpythonfile.py(5): for item in mylist: myfirstpythonfile.py(6): print item 19 myfirstpythonfile.py(5): for item in mylist: myfirstpythonfile.py(6): print item 3 myfirstpythonfile.py(5): for item in mylist: --- modulename: trace, funcname: _unsettrace trace.py(80): sys.settrace(None) </code></pre> <p>Which as we can see, traces the exact line of python code, executes the result immediately after and outputs it into stdout.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload