Hi Marc,

Why not use the latest release on Windows ?

The callbacks are broken on 2.0.x (and have always been so).
It is somewhere in the documentation
(http://rpy.sourceforge.net/rpy2/doc/html/overview.html#test-an-installation)
but should certainly be also mentioned in the section about callbacks
(http://rpy.sourceforge.net/rpy2/doc/html/rinterface.html#i-o-with-the-r-console).
I will add a note to that later section.

Now to have you going you can either:
- start using the version 2.1-dev (callbacks are supposed to work)
- use a trick similar to the in RObjectMixin (see below) for the console 
ouput
     def __str__(self):
         if sys.platform == 'win32':
             tfile = baseNameSpaceEnv["tempfile"]()
             tmp = baseNameSpaceEnv["file"](tfile, open="w")
         else:
             tmp = baseNameSpaceEnv["fifo"]("")
         baseNameSpaceEnv["sink"](tmp)
         r.show(self)
         baseNameSpaceEnv["sink"]()
         if sys.platform == 'win32':
             baseNameSpaceEnv["close"](tmp)
             tmp = baseNameSpaceEnv["file"](tfile, open="r")
         s = baseNameSpaceEnv["readLines"](tmp)
         if sys.platform == 'win32':
             baseNameSpaceEnv["close"](tmp)
             baseNameSpaceEnv["unlink"](tfile)
         else:
             r.close(tmp)
         s = str.join(os.linesep, s)
         return s


L.





Carson Farmer wrote:
> Hi List,
> 
> Apologies if this has already been covered, I didn't see anything in the 
> archives...
> 
> I seem to be having trouble getting rinterface.setWriteConsole to work 
> for me on Windows...
> 
> rpy2.__version__
> '2.0.6' (Linux)
> '2.0.3' (Windows)
> 
> For example, on Windows I get:
>  >>> import rpy2.robjects as robs
>  >>> result = robs.r("print(c(1,2,3,4,5))")
> [1] 1  2  3  4  5
>  >>> def f(output):
> ...     print "****"
> ...     print output
> ...     print "****"
> ...
>  >>> robs.rinterface.setWriteConsole(f)
>  >>> result = robs.r("print(c(1,2,3,4,5))")
> [1] 1  2  3  4  5
> 
> Whereas on Linux, I get:
>  >>> import rpy2.robjects as robs 
>  >>> result = robs.r("print(c(1,2,3,4,5))")
> [1] 1 2 3 4 5
>  >>> def f(input):
> ...     print "****"
> ...     print input
> ...     print "****"
> ...
>  >>> robs.rinterface.setWriteConsole(f)
>  >>> result = robs.r("print(c(1,2,3,4,5))")
> ****
> [1]
> ****
> ****
>  1
> ****
> ****
>  2
> ****
> ****
>  3
> ****
> ****
>  4
> ****
> ****
>  5
> ****
> ****
> 
> 
> ****
> 
> Am I doing something wrong here?
> Is there some kind of workaround to get these working similarly (as in 
> the Linux case)?
> 
> Thanks for any advice,
> 
> Carson
> 


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to