Currently the default handler for R console output simply passes the
strings to 'print'.  The problem with this is that 'print' adds a
newline at the end of each string it outputs.  Since it turns out that
R functions like to trickle their output out over multiple calls, this
causes things to be horribly mangled.  For instance, here's an excerpt
from r["print"] called on a lm summary object:

--------------------
Coefficients:


 Estimate
 Std. Error
 t value
 Pr(>|t|)

(Intercept)
    44.32
     263.07
   0.168
    0.873

x
    43.32
      72.96
   0.594
    0.579
-------------------

This patch switches to using sys.stdout.write instead.  With the
patch, the output is:

-------------------
Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)    44.32     263.07   0.168    0.873
x              43.32      72.96   0.594    0.579
-------------------

Which is somewhat preferable.
diff -r b08b47242d73 rpy/rinterface/__init__.py
--- a/rpy/rinterface/__init__.py	Sat Jan 24 15:14:10 2009 +0100
+++ b/rpy/rinterface/__init__.py	Mon Jan 26 01:37:20 2009 -0800
@@ -97,16 +97,15 @@
         super(BoolSexpVector, self).__init__(v, LGLSXP)
 
 
-# wrapper because 'print' is strangely not a function
-# Python prior to version 3.0
+# wrapper in case someone changes sys.stdout:
 def consolePrint(x):
-    """ Wrapper around Python's print. This is the default callback for R's console. """
-    print(x)
+    """This is the default callback for R's console. It simply writes to stdout."""
+    sys.stdout.write(x)
 
 setWriteConsole(consolePrint)
 
 def consoleFlush():
-    pass
+    sys.stdout.flush()
 
 setFlushConsole(consoleFlush)
 
@@ -118,7 +117,7 @@
 setReadConsole(consoleRead)
 
 def consoleMessage(x):
-    print(x)
+    sys.stdout.write(x)
 setShowMessage(consoleMessage)
 
 
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to