R Statistics Package into Sage !?

11 views
Skip to first unread message

William Stein

unread,
Nov 26, 2007, 1:07:13 AM11/26/07
to sage-...@googlegroups.com
Hi,

Mike Hansen and I have put some work into making it possible to very
easily use R from Sage, and are
even maybe considering including R in Sage. This is very likely
definitely not ready yet, but we
have an experimental package that might work. It would be very
useful if some people could test
building it and report back whether or not it works, and how long it
takes to build.

All you have to do is:

(1) install R:

$ time ./sage -f -m r-2.6.1rc.p1

NOTE: If the package name changes, type

$ ./sage -experimental |grep r-

to see what the new name is. Note that we put "-f -m" above so that the R build
directory gets left laying around in spkg/build/. This is because
there are still some
issues with "make install" and R. Also, R hardcodes install paths
in the R command,
which is something we'll have to deal with before releasing R as an
official optional
package.

(2)
Then to test it out see if this works:

sage: import rpy
sage: rpy.r.t_test(range(100))
{'alternative': 'two.sided',
'conf.int': [43.743490583064158, 55.256509416935835],
'data.name': '0:99',
'estimate': {'mean of x': 49.5},
'method': 'One Sample t-test',
'null.value': {'mean': 0.0},
'p.value': 3.0537578007169442e-31,
'parameter': {'df': 99.0},
'statistic': {'t': 17.062204191756354}}


sage: time rpy.r.t_test(range(1000000))
CPU times: user 1.97 s, sys: 0.12 s, total: 2.08 s
Wall time: 2.09
{'alternative': 'two.sided',
'conf.int': [499433.7061652476, 500565.2938347524],
'data.name': '0:999999',
'estimate': {'mean of x': 499999.5},
'method': 'One Sample t-test',
'null.value': {'mean': 0.0},
'p.value': 0.0,
'parameter': {'df': 999999.0},
'statistic': {'t': 1732.0482094941815}}

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

William Stein

unread,
Nov 26, 2007, 1:14:58 AM11/26/07
to sage-...@googlegroups.com
On Nov 25, 2007 10:07 PM, William Stein <wst...@gmail.com> wrote:
> Mike Hansen and I have put some work into making it possible to very
> easily use R from Sage, and are
> even maybe considering including R in Sage. This is very likely
> definitely not ready yet, but we
> have an experimental package that might work. It would be very
> useful if some people could test
> building it and report back whether or not it works, and how long it
> takes to build.

Responding to myself. R builds on ppc osx10.4 but rpy doesn't yet:

gcc -bundle -undefined dynamic_lookup
build/temp.macosx-10.3-ppc-2.5/src/rpymodule2061.o
build/temp.macosx-10.3-ppc-2.5/src/R_eval2061.o build/temp.macos
x-10.3-ppc-2.5/src/io2061.o
-L/Users/was/sage-2.8.14.rc1/spkg/build/r-2.6.1rc.p1/src/bin
-L/Users/was/sage-2.8.14.rc1/spkg/build/r-2.6.1rc.p1/src/lib -L/
Users/was/sage-2.8.14.rc1/local/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/
-L/Users/was/sage-2.8.14.rc1/spkg/build/r-2.6.1rc.p1/src/bin
-L/Users/was/sage
-2.8.14.rc1/spkg/build/r-2.6.1rc.p1/src/lib
-L/Users/was/sage-2.8.14.rc1/local/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/
-lR -lf95 -o build/lib.macosx-1
0.3-ppc-2.5/_rpy2061.so
/usr/bin/ld: warning can't open dynamic library: libRblas.dylib
referenced from:
/Users/was/sage-2.8.14.rc1/spkg/build/r-2.6.1rc.p1/src/lib/libR.dylib
(c
hecking for undefined symbols may be affected) (No such file or
directory, errno = 2)
/usr/bin/ld: Undefined symbols:
_dgemm_ referenced from libR expected to be defined in libRblas.dylib
_dsyrk_ referenced from libR expected to be defined in libRblas.dylib
_zgemm_ referenced from libR expected to be defined in libRblas.dylib
_dcopy_ referenced from libR expected to be defined in libRblas.dylib
_dtrsm_ referenced from libR expected to be defined in libRblas.dylib
_daxpy_ referenced from libR expected to be defined in libRblas.dylib
_dswap_ referenced from libR expected to be defined in libRblas.dylib
_ddot_ referenced from libR expected to be defined in libRblas.dylib
__g95_sign_r8 referenced from libR expected to be defined in libRblas.dylib
_dasum_ referenced from libR expected to be defined in libRblas.dylib
_dscal_ referenced from libR expected to be defined in libRblas.dylib
_dnrm2_ referenced from libR expected to be defined in libRblas.dylib
_drot_ referenced from libR expected to be defined in libRblas.dylib
_drotg_ referenced from libR expected to be defined in libRblas.dylib
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

real 0m3.647s
user 0m1.476s
sys 0m0.957s
sage: An error occurred while installing rpy-1.0-rc3-p1
Please email sage-devel http://groups.google.com/group/sage-devel
explaining the problem and send the relevant part of
of /Users/was/sage-2.8.14.rc1/install.log. Describe your computer,
operating system, etc.
If you want to try to fix the problem, yourself *don't* just cd to
/Users/was/sage-2.8.14.rc1/spkg/build/rpy-1.0-rc3-p1 and type 'make'.
Instead type "/Users/was/sage-2.8.14.rc1/sage -sh"
in order to set all environment variables correctly, then cd to
/Users/was/sage-2.8.14.rc1/spkg/build/rpy-1.0-rc3-p1
(When you are done debugging, you can type "exit" to leave the
subshell.)

Mike Hansen

unread,
Nov 26, 2007, 1:40:23 AM11/26/07
to sage-...@googlegroups.com
The build worked for me on 64-bit Linux. It took 14 minutes and 30
seconds to download and install. The examples you gave worked fine:

sage: sage: import rpy
sage: sage: rpy.r.t_test(range(100))


{'alternative': 'two.sided',
'conf.int': [43.743490583064158, 55.256509416935835],
'data.name': '0:99',
'estimate': {'mean of x': 49.5},
'method': 'One Sample t-test',
'null.value': {'mean': 0.0},
'p.value': 3.0537578007169442e-31,
'parameter': {'df': 99.0},
'statistic': {'t': 17.062204191756354}}

sage: sage: time rpy.r.t_test(range(1000000))
CPU times: user 3.03 s, sys: 0.09 s, total: 3.12 s
Wall time: 3.17


{'alternative': 'two.sided',
'conf.int': [499433.7061652476, 500565.2938347524],
'data.name': '0:999999',
'estimate': {'mean of x': 499999.5},
'method': 'One Sample t-test',
'null.value': {'mean': 0.0},
'p.value': 0.0,
'parameter': {'df': 999999.0},
'statistic': {'t': 1732.0482094941815}}

But, it doesn't look like my patch to rpy was applied:

sage: rpy.r(2r)
2.0
sage: rpy.r(2)
---------------------------------------------------------------------------
<class 'rpy.RException'> Traceback (most recent call last)

/home/mike/src/rpy-1.0-RC3/<ipython console> in <module>()

/opt/sage/local/lib/python2.5/site-packages/rpy.py in __call__(self, s)
297
298 def __call__(self, s):
--> 299 return self.eval(self.parse(text=s))
300
301 def __help__(self, *arg, **kw):

<class 'rpy.RException'>: cannot convert from type 'sage.rings.integer.Integer'

There should be an rpymodule.c in the patches/ directory in
rpy-1.0-RC3 in my home directory on sage.math which makes it so that
rpy will check for a _rpy_ method to convert a Sage object to an rpy
one.

--Mike

mabshoff

unread,
Nov 26, 2007, 3:14:55 AM11/26/07
to sage-devel
Those are BLAS symbols, but how come R doesn't use the accelerate
FramWork for that?

Cheers,

Michael


> collect2: ld returned 1 exit status
> error: command 'gcc' failed with exit status 1
>
> real 0m3.647s
> user 0m1.476s
> sys 0m0.957s
> sage: An error occurred while installing rpy-1.0-rc3-p1
> Please email sage-develhttp://groups.google.com/group/sage-devel

Jaap Spies

unread,
Nov 26, 2007, 6:44:55 AM11/26/07
to sage-...@googlegroups.com
William Stein wrote:

> even maybe considering including R in Sage. This is very likely
> definitely not ready yet, but we
> have an experimental package that might work. It would be very
> useful if some people could test
> building it and report back whether or not it works, and how long it
> takes to build.
>

real 13m21.698s
user 11m28.544s
sys 1m2.623s
Successfully installed r-2.6.1rc.p1
You can safely delete the temporary build directory
/home/jaap/downloads/sage-2.8.14/spkg/build/r-2.6.1rc.p1
Making SAGE/Python scripts relocatable...
Making script relocatable

real 14m18.586s
user 11m37.323s
sys 1m3.829s

Examples worked OK

THis is on Fedora 7:
Linux paix 2.6.23.1-21.fc7 #1 SMP Thu Nov 1 21:09:24 EDT 2007 i686 i686 i386 GNU/Linux

Jaap

mhampton

unread,
Dec 5, 2007, 8:34:10 AM12/5/07
to sage-devel
I was too busy for the last couple of weeks to help seriously with
this, but I did try to install it on my PPC apple laptop and my Intel
OS X 10.4 desktop. It failed on both; the PPC problem is probably the
same as you mentioned. I will post the errors from the intel machine
when I get a chance.

I think its great that you guys started working on this; I think it
would help Sage a lot if we can say there is support for R before we
go to the joint meetings.

-Marshall Hampton
> Please email sage-develhttp://groups.google.com/group/sage-devel

William Stein

unread,
Dec 8, 2007, 6:10:05 AM12/8/07
to sage-...@googlegroups.com
Hi,

I've posted a new R 2.6.1 package. To try it do

sage -i r-2.6.1

It should build in about 5-6 minutes. WARNING: This still
doesn't quite work on OSX10.4 yet -- it may fail building rpy at
the very end, despite saying that it succeeds. Even on OSX10.4,
R builds fine (just not the rpy interface).

A simple test that everything built and works is

sage: import rpy
sage: rpy.r.t_test(range(100))
{'alternative': 'two.sided',
'conf.int': [43.743490583064158, 55.256509416935835],
'data.name': '0:99',
'estimate': {'mean of x': 49.5},
'method': 'One Sample t-test',
'null.value': {'mean': 0.0},
'p.value': 3.0537578007169442e-31,
'parameter': {'df': 99.0},
'statistic': {'t': 17.062204191756354}}

You can also do

sage: !R

to run R itself.

Notes:
* R should now pick up X libraries if you have the devel headers, so you'll
be able to do graphics.
* this is a newer version of R than the last package
* I changed the build to only build the core packages and not the
recommended optional ones -- building those adds up to 15 minutes
to the build time, and isn't really needed to get on our feet
regarding R support.
* It is not necessary to do "sage -f -m r-2.6.1" like before, since
the correct directly is copied over.

Problems:
* too much is installed -- in particular local/lib/r/src should probably
be deleted.
* Probably the path is hardcoded -- this can be fixed by modifying
local/bin/R slightly to use SAGE_LOCAL.
* rpy isn't properly patched so that rpy.r.t_test([1..100]) works.
* the pexpect interface isn't done (mike hansen is hard at work on it)
* osx 10.4 support
* gfortran support

William

mhampton

unread,
Dec 9, 2007, 12:14:48 PM12/9/07
to sage-devel
Hi,

I just tried installing the new package on a PPC apple laptop, and got
the following errors (I think they are the same as you listed before):

/usr/bin/ld: warning can't open dynamic library: libRblas.dylib
referenced from: /Users/mh/sage-2.8.4.1/local/lib/r/lib/libR.dylib
(checking for undefined symbols may be affected) (No such file or
directory, errno = 2)
/usr/bin/ld: Undefined symbols:
_dgemm_ referenced from libR expected to be defined in libRblas.dylib
_dsyrk_ referenced from libR expected to be defined in libRblas.dylib
_zgemm_ referenced from libR expected to be defined in libRblas.dylib
_dcopy_ referenced from libR expected to be defined in libRblas.dylib
_dtrsm_ referenced from libR expected to be defined in libRblas.dylib
_daxpy_ referenced from libR expected to be defined in libRblas.dylib
_dswap_ referenced from libR expected to be defined in libRblas.dylib
_ddot_ referenced from libR expected to be defined in libRblas.dylib
__g95_sign_r8 referenced from libR expected to be defined in
libRblas.dylib
_dasum_ referenced from libR expected to be defined in libRblas.dylib
_dscal_ referenced from libR expected to be defined in libRblas.dylib
_dnrm2_ referenced from libR expected to be defined in libRblas.dylib
_drot_ referenced from libR expected to be defined in libRblas.dylib
_drotg_ referenced from libR expected to be defined in libRblas.dylib
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
Error building RPY -- Python interface to R.

real 0m12.407s
user 0m2.730s
sys 0m1.237s
sage: An error occurred while installing rpy-1.0.1

William Stein

unread,
Dec 9, 2007, 12:20:47 PM12/9/07
to sage-...@googlegroups.com
On Dec 9, 2007 9:14 AM, mhampton <hamp...@gmail.com> wrote:
>
> Hi,
>
> I just tried installing the new package on a PPC apple laptop, and got
> the following errors (I think they are the same as you listed before):

We have yet another even new package that does install fine on ppc:

sage -i r-2.6.1.p1

Please give it a short. I just tested...

-- William

Reply all
Reply to author
Forward
0 new messages