Menu

#53 Plotting with RPy crashes Python

rpy
closed
Win32 (20)
5
2019-12-19
2006-02-16
Anonymous
No

When I type the following code into python, and wait
for R to connect to the display, an R window pops up
with nothing inside.

from rpy import *

x = range(0, 10)
y = [ 2*i for i in x ]

r.plot_default(x, y)

I am able to output my graphs to a postscript file,
but I can not look at them directly. When I close the
window, the title message becomes R Graphics: Device
2 (not responding...), and once the window closes -
my python session restarts itself (crashes). I am
using R 2.2.1 and Python 2.4 in Windows XP
Professional. What could be the cause of this problem?

Discussion

  • timbo

    timbo - 2006-02-16

    Logged In: YES
    user_id=1453961

    I'm having the same problem. I just installed rpy today
    under the same set up as yours. All the R functions (the
    ones that I use) seem to be working except for the plot
    command (python crashs).

    However, if I issue the r.par() command, the graphics window
    opens, but crashes when I try to plot to it. If I have time
    today, I'll set it up on my linux side and see if it works
    there.

     
    • Anonymous

      Anonymous - 2019-12-14
      Post awaiting moderation.
    • Anonymous

      Anonymous - 2019-12-19
      Post awaiting moderation.
  • Nobody/Anonymous

    Logged In: NO

    I have not been able to plot with RPy under any version of
    Windows... try Linux.

     
  • DGingrich

    DGingrich - 2006-02-23

    Logged In: YES
    user_id=1460088

    I have the same problem. The Rpy manual recommends using
    IDLE as opposed to the console
    (http://rpy.sourceforge.net/rpy/doc/manual_html/Caveat-and-bugs.html#Caveat-and-bugs).
    Personally, I can run the plotting tutorial
    (http://rpy.sourceforge.net/plotting-with-RPy.html)from the
    ActivePython 2.4 IDE.

    This was also a thread on the R mailing list:
    (http://tolstoy.newcastle.edu.au/R/devel/06/01/3708.html).
    This thread generated a potential cause
    (http://tolstoy.newcastle.edu.au/R/devel/06/01/3709.html#3711qlink1)
    as well as a potential workaround
    (http://tolstoy.newcastle.edu.au/R/devel/06/01/3711.html),
    ("r.options(windowsBuffered=False)")

    Using the work around, the plot window is populated from the
    console, but can't be manipulated. Further, if it's closed
    it closes the python interpreter.

    I tried combining the workaround with the suggested event
    loop from the rpy manual:

    $ python
    ActivePython 2.4 Build 243 (ActiveState Corp.) based on
    Python 2.4 (#60, Nov 30 2004, 09:34:21) [MSC v.1310 32 bit
    (Intel)]
    on win32
    Type "help", "copyright", "credits" or "license" for more
    information.

    from rpy import *
    r.options(windowsBuffered=False)
    {'windowsBuffered': True}
    x = range(1,10)
    y = [i * 2 for i in x]
    r.plot_default(x,y)
    while 'windows' in r_events():
    ... pass
    ...
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    SystemError: error return without exception set

    But get the exception shown and no change in behavior of the
    plot window. Note that repeated calls to plot do reflect in
    the plot window. E.g.

    r.plot(x, [i*i for i in x])

    Changes the graph to a display a parabola.

    Until the full problem is fixed, it's probably worthwhile to
    update the documentation (& FAQ?) with a specific warning
    about plotting from the Win32 Python console.

     
  • Nobody/Anonymous

    Logged In: NO

    Try:

    r.options(windowsBuffered=False)#this is what you need
    r.plot_default(x, y) # whatever you are trying to plot
    r.dev_off() # closes plot window

    Alisha Rossi

     
  • Gregory Warnes

    Gregory Warnes - 2006-02-28

    Logged In: YES
    user_id=9316

    The next release of RPy will automatically perform
    "r.options(windowsBuffered=False)"
    to help avoid this problem.

    Also, it is generally a good idea to use "dev.off()" to
    close a graphics window rather than closing it using the
    window controls.

    -G

     
  • Anonymous

    Anonymous - 2019-03-05

    try the following workaround, works even in 2019 :)

    pp = ggplot2.ggplot(mtcars) + \ ggplot2.aes_string(x='wt', y='mpg', col='factor(cyl)') + \ ggplot2.geom_point() + \ ggplot2.geom_smooth(ggplot2.aes_string(group = 'cyl'),
    method = 'lm')

    //if a plot is barely or not shown in the preview:
    //load the plot twice and use r.windows() in between
    //then use grdevices.dev_off() twice and choose waiting time in between

    rprint(pp)
    r.windows()
    rprint(pp)
    grdevices.dev_off()
    time.sleep(10)
    grdevices.dev_off()

    //and p.s.: if the window still crashes, just execute grdevices.dev_off(), no need to force close it

     

Anonymous
Anonymous

Add attachments
Cancel