calling python from R with instant output to console
Question: I run python scripts from R using the R command:

    
    
    system('python test.py')
    

But my print statements in test.py do not appear in the R console until the
python program is finished. I would like to view the print statements as the
python program is running inside R. I have also tried `sys.stdout.write()`,
but the result is the same. Any help is greatly appreciated.

Here is my code for test.py:

    
    
    import time
    
    for i in range(10):
      print 'i=',i
      time.sleep(5)
    


Answer: Tested on Windows 8 with R v3.0.1

Simply right click on the r console then **untick/unselect** the `Buffered
Output` option (See image below). Now execute your code you shall see the
output of `print` statements!

![image-file](http://i.stack.imgur.com/jRK2Q.png)

Update:

I forgot to mention that I also needed to add `sys.stdout.flush()` after the
`print` statement in the python file.

    
    
    import time
    import sys
    
    for i in range(5):
        print 'i=',i
        sys.stdout.flush()
        time.sleep(1)
    

Also if you select the `Buffered Output` option then when you left click on
the r console while your script is executing you shall see the output. Keep
clicking and the output is shown. :)

