Hi,

Sage is a great tool. I've been waiting for R/rpy integration and I see that
recent versions have R/rpy bundled. One problem I've encountered is that
basic plotting with rpy in sage doesn't seem to work -- however, I've got a
simple workaround which might be worth posting somewhere.

Here's the machine & version info:

[balajis:~]$uname -a
Darwin Macintosh-8.local 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun 9
19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386 i386 MacBookPro1,1
Darwin

[balajis:~]$sage -v
| SAGE Version 3.1.1, Release Date: 2008-08-17


And here's the example bug: *No output is generated when I run
r.hist(r.rnorm(20))*.

[balajis:~]$sage
----------------------------------------------------------------------
| SAGE Version 3.1.1, Release Date: 2008-08-17 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: r.rnorm(20)

[1] -0.49087837 -1.94011412 1.71741910 -0.89248178 0.73915490 -0.46471049
-0.42553938 0.46196391
[9] 0.33025458 1.02435878 -1.12997555 -0.08253489 -1.59833466 1.32528999
-0.32348019 2.29304930
[17] -0.54705933 0.10793088 1.28371034 0.36289179
sage: r.hist(r.rnorm(20),xlab="",ylab="",main="")
[1] 20

This *should* be generating a plot and a histogram object, but it's just
returning the number of arguments. Here's a workaround which does what I
want -- note that I call it "rr" so it doesn't overlap with the built-in r.

[balajis:~]$sage
----------------------------------------------------------------------
| SAGE Version 3.1.1, Release Date: 2008-08-17 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: from rpy import r as rr
sage: rr.rnorm(10)

[-0.58609553556082361,
-0.075660923360481733,
-0.69609524980131876,
1.7004392323744253,
-1.5274655764987806,
-1.6461045004296775,
-0.6132766826900824,
0.0019692315208043763,
1.309716715308654,
-1.1077072723136909]
sage: rr.hist(rr.rnorm(10),xlab="",ylab="",main="")

{'breaks': [-1.5, -1.0, -0.5, 0.0, 0.5, 1.0],
'counts': [2, 2, 1, 2, 3],
'density': [0.39999992000001605,
0.40000000000000008,
0.20000000000000001,
0.40000000000000002,
0.60000000000000009],
'equidist': True,
'intensities': [0.39999992000001605,
0.40000000000000008,
0.20000000000000001,
0.40000000000000002,
0.60000000000000009],
'mids': [-1.25, -0.75, -0.25, 0.25, 0.75],
'xname': 'c(0.98537142230916, -0.748763617907383, -0.527738177570716,
-0.186196733768228, 0.911294217964427, -1.45795735527173, 0.343719696116503,
0.0333727688883639, -1.06629162286718, 0.932158759550036)'}

A plot is also displayed, though it's an X11 plot generated by the rpy
module rather than one of sage's pngs. This is a hack but a decent one,
which allows integration of existing R/rpy code with sage libraries.

One important caveat: moving around the X11 window or doing anything which
causes a refresh can result in "bus errors" like the following. This seems
particularly frequent when calling rpy without the xlab="",ylab="",main=""
keyword arguments for the plot, as then there's a lot of cruft all over the
X11 window.

sage: rr.hist(rr.rnorm(100))

{'breaks': [-3.0,
-2.5,
-2.0,
...
-1.84307690299984, 0.145126483019115)'} #UP to this point, normal output of
hist
sage: Error during wrapup: #<----  Now the errors start
*** caught bus error ***

*** caught bus error ***

*** caught bus error ***

*** caught bus error *** #<--- several Ctrl-C's required to get to this
point

Fatal Python error: GC object already tracked
*** caught bus error ***
address 0x2c, cause 'non-existent physical address'

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: /Applications/sage/local/bin/sage-sage: line 216: 2535 Abort trap
sage-ipython "$@" -c "$SAGE_STARTUP_COMMAND;"
[balajis:~]$ #<--------   Eventually dumps me to the prompt

Any ideas on how to fix this? R has a lot of powerful visualization
capabilities and it'd be great to call it from within sage without
problems...


--B

-- 
Balaji S. Srinivasan, Ph.D.
Stanford University
Visiting Scholar, Depts. of Statistics and Computer Science
318 Campus Drive, Clark Center S251
(650) 380-0695
[EMAIL PROTECTED]
http://jinome.stanford.edu

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to