R plot display problem under windows when using python rpy module.

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

R plot display problem under windows when using python rpy module.

Bo Peng-2
Dear list,

Rpy is a python module that provides python interface to R. The
following simple commands

>>> from rpy import *
>>> r.plot(0)

is supposed to create a window that displays the result of plot(0).

However, we observe that
1. Under *nix, rpy+R+python  work as expected
2. Under windows, python + pythonWin32 (a python GUI provided by the
pywin32 module), work as expected
3. Under windows, if we run the commands from command line or IDLE (a
simple python IDE), a window will be created, but the figure will not
be drawn. Then, if we run r.plot(2), the result of plot(0) will be
drawn. plot(2) will be displayed when the next drawing command is
executed.

Since R works well in most cases, I do not think this is a R problem.
However, can anyone tell me what *might* block the figures from being
displayed? In other word, what might PythonWin have provided to enable
correct rendering of the figures? If I have to trace to the sources,
what portion of the R code should I have a look at? (It is good that
python/R/rpy are all open source).

Many thanks in advance.
Bo

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R plot display problem under windows when using python rpy module.

Brian Ripley
How is Rpy calling R?  Presumably R is running single-threaded, and the
problem is likely to be that Rpy is using blocking I/O on the R process
and hence blocking the GUI callbacks that drive the window.

The not-so-simple answer is not to do it that way.  It might be well
sufficient to turn windows() buffering off -- see its help page.

On Mon, 9 Jan 2006, Bo Peng wrote:

> Dear list,
>
> Rpy is a python module that provides python interface to R. The
> following simple commands
>
>>>> from rpy import *
>>>> r.plot(0)
>
> is supposed to create a window that displays the result of plot(0).
>
> However, we observe that
> 1. Under *nix, rpy+R+python  work as expected
> 2. Under windows, python + pythonWin32 (a python GUI provided by the
> pywin32 module), work as expected
> 3. Under windows, if we run the commands from command line or IDLE (a
> simple python IDE), a window will be created, but the figure will not
> be drawn. Then, if we run r.plot(2), the result of plot(0) will be
> drawn. plot(2) will be displayed when the next drawing command is
> executed.
>
> Since R works well in most cases, I do not think this is a R problem.
> However, can anyone tell me what *might* block the figures from being
> displayed? In other word, what might PythonWin have provided to enable
> correct rendering of the figures? If I have to trace to the sources,
> what portion of the R code should I have a look at? (It is good that
> python/R/rpy are all open source).
>
> Many thanks in advance.
> Bo
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R plot display problem under windows when using python rpy module.

Bo Peng-2
On 1/9/06, Prof Brian Ripley <[hidden email]> wrote:
> How is Rpy calling R?  Presumably R is running single-threaded, and the
> problem is likely to be that Rpy is using blocking I/O on the R process
> and hence blocking the GUI callbacks that drive the window.
>
> The not-so-simple answer is not to do it that way.  It might be well
> sufficient to turn windows() buffering off -- see its help page.

Using
>>> from rpy import *
>>> r.options(windowsBuffered=False)
>>> r.plot(0)
solves the problem.

Thank you very much! I will suggest that rpy developers address this problem.

Bo

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R plot display problem under windows when using python rpy module.

Hin-Tak Leung-2
In reply to this post by Bo Peng-2
Hi,
(off topic slightly, and a slight flame-bait...).
I don't have an answer or clue to your question, but I have played with
PSPython briefly and it did work somewhat for me (and I have not heard
of rpy until reading this through r-devel), and I was wondering
what is the difference between rpy and RSPython. According to the rpy page:
=============
  This code is inspired by RSPython from the Omegahat project. The main
goals of RPy are:

     * to have a very robust interface for using R from Python
     * the interface should be as transparent and easy to use as possible
     * it should be usable for real scientific and statistical computations
=============

But "a very robust interface" is self-proclaimed and unsubstantiated;
"transparent", "easy to use", "usable for real scientific..." are
subjective, so what it amounts to is a case of "not-invented-here"
symptom (i.e. wheels...). This might be flame-bait... but since I
have used PSPython very very briefly and I don't think it suffers
from the above 3 (and even if it does, it is open-source, one can
always add/modify/patch without starting new), I do wonder...

So I have a question for you - why rpy instead of RSPython? Have you
tried both, and can you give a comparison of pros and cons?

In fact, the most obvious superficial difference I can see is that
RSPython is written by an R-biased person (it uses "R CMD build"), where
as rpy is written by a Python-biased person (it builds with
"python setup.py ...")... there is nothing wrong with having a bias,
but the goals listed imply that it might be "better" in those areas...
which may or may not be true.

(To answer one question you might have, I was trying to invoke Python
code from inside R and was doing it the opposite direction from you).

HTL

Bo Peng wrote:

> Dear list,
>
> Rpy is a python module that provides python interface to R. The
> following simple commands
>
>
>>>>from rpy import *
>>>>r.plot(0)
>
>
> is supposed to create a window that displays the result of plot(0).
>
> However, we observe that
> 1. Under *nix, rpy+R+python  work as expected
> 2. Under windows, python + pythonWin32 (a python GUI provided by the
> pywin32 module), work as expected
> 3. Under windows, if we run the commands from command line or IDLE (a
> simple python IDE), a window will be created, but the figure will not
> be drawn. Then, if we run r.plot(2), the result of plot(0) will be
> drawn. plot(2) will be displayed when the next drawing command is
> executed.
>
> Since R works well in most cases, I do not think this is a R problem.
> However, can anyone tell me what *might* block the figures from being
> displayed? In other word, what might PythonWin have provided to enable
> correct rendering of the figures? If I have to trace to the sources,
> what portion of the R code should I have a look at? (It is good that
> python/R/rpy are all open source).
>
> Many thanks in advance.
> Bo
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R plot display problem under windows when using python rpy module.

Bo Peng-2
> I was wondering
> what is the difference between rpy and RSPython.

The main difference is that rpy does one-way communication, is simpler
than RSPython, than is easier to use.

> So I have a question for you - why rpy instead of RSPython? Have you
> tried both, and can you give a comparison of pros and cons?

I am not an expert on RSPython. I tried RSPython and rpy and chose rpy
for the following reasons:

1. rpy is in active maintenance. As you can see from rpy webpage, rpy
supports all versions of R till 2.2.1, python 2.4 and provides binary
installers like rpy-0.4.6-R-2.0.0-to-2.2.1-xxxx.xxx . On the contrary,
a windows installer for RSPython is for R-1.4.0, python 2.2.0.

2. RSPython uses mainly its RS.call function. This is troublesome and
is the main reason why I use rpy. For example,

in RSPython:
  RS.call('rnorn', 10)
in rpy:
  r.rnorm(10)

RSPython does provide similar usage now (maybe after I became a rpy user) but
RSPython:
  from RS import R
  R.rnorm(10)   # works
  R.dev.off()     # does not work

Rpy solves this problem by (and the mechanism is clearly described in
the rpy manual):
  from rpy import *
  r.rnorm(10)
  r.dev_off()

rpy also provides
  r('''arbitrary R piece of code''')
which is immensely useful to run big trunk of R code.

rpy also claims that the performance of rpy is better but I have no
comparison data here.

>  there is nothing wrong with having a bias,
> but the goals listed imply that it might be "better" in those areas...
> which may or may not be true.

I agree.

> (To answer one question you might have, I was trying to invoke Python
> code from inside R and was doing it the opposite direction from you).

Exactly. We are doing different things so while you have to use
RSPython, I have a choice between RSPython and rpy. In my case, all
the real computations are done in C/C++, wrapped by Python. I could
have wrapped my C/C++ code in R but R is not good at wrapping C++
class hierarchy because of the different OOP mechanisms. When I need
the statistical analysis and plotting capacity of R, I use rpy.

As a matter of fact, since Python is a powerful programming language
than can handle string, text file etc better than R, I usually prepare
my data in python  and pass them to R using rpy.

Cheers,
Bo

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R plot display problem under windows when using python rpy module.

Hin-Tak Leung-2
Thanks a lot for the comment and discussion. A few of mine below.

Bo Peng wrote:
<snipped older inserts>
> The main difference is that rpy does one-way communication, is simpler
> than RSPython, than is easier to use.
>
<snipped older inserts>
>
> I am not an expert on RSPython. I tried RSPython and rpy and chose rpy
> for the following reasons:
>
> 1. rpy is in active maintenance. As you can see from rpy webpage, rpy
> supports all versions of R till 2.2.1, python 2.4 and provides binary
> installers like rpy-0.4.6-R-2.0.0-to-2.2.1-xxxx.xxx . On the contrary,
> a windows installer for RSPython is for R-1.4.0, python 2.2.0.

I think my original comment regarding not-invented-here still applies -
it is a shame that much of the omegahat project is defunc, but it
doesn't mean that somebody interested in a particular orphaned project
can't take it over or fork it or enhance on top. I suspect a small part
of simpler/easier comes from it being smaller and younger, which is
exactly why one should think carefully about the "wheel"...

>
> 2. RSPython uses mainly its RS.call function. This is troublesome and
> is the main reason why I use rpy. For example,
>
> in RSPython:
>   RS.call('rnorn', 10)
> in rpy:
>   r.rnorm(10)
>
> RSPython does provide similar usage now (maybe after I became a rpy user) but
> RSPython:
>   from RS import R
>   R.rnorm(10)   # works
>   R.dev.off()     # does not work

Maybe " R.dev("off") " ? Wild-guess here.

>
> Rpy solves this problem by (and the mechanism is clearly described in
> the rpy manual):
>   from rpy import *
>   r.rnorm(10)
>   r.dev_off()
>
> rpy also provides
>   r('''arbitrary R piece of code''')
> which is immensely useful to run big trunk of R code.

It might be RS.eval("...")? Again wild-guess here.

The "RS.call('routine', parameter)" syntax is actually how interpreted R
code interacts with compiled C routines in much of R itself.

I think this difference is very much about which language one is more at
home with.

(My background is actually somewhat stronger with Python than R, and
I was trying to learn R's C interfaces by looking at how R
interacts with more familiar languages like Perl/Python/Java)

<snipped>
>
> Exactly. We are doing different things so while you have to use
> RSPython, I have a choice between RSPython and rpy. In my case, all
> the real computations are done in C/C++, wrapped by Python. I could
> have wrapped my C/C++ code in R but R is not good at wrapping C++
> class hierarchy because of the different OOP mechanisms. When I need
> the statistical analysis and plotting capacity of R, I use rpy.

That's correct - C++ together with R is quite painful, and I can imagine
C++/Python being easier. (C++/R I have a little 1st hand experience
with, and I don't for C++/Python).

> As a matter of fact, since Python is a powerful programming language
> than can handle string, text file etc better than R, I usually prepare
> my data in python  and pass them to R using rpy.

Thanks. That's useful to know.

HTL

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel