Sunday, March 28, 2010

Eclipse setup notes: R (StatEt) and Python (Sage)

My standard Eclipse setup consists of the following extensions:
  • Texclipse
  • StatEt (for R and Sweave)
  • Pydev
  • Data Tools
  • BIRT
And I also have these loaded, even if I don't use them as much
  • CDT (C/C++ Developers tools)
  • Java (since it comes with)
  • Subversion
For a while I've been using StatEt using the R console, because I had not gotten the RJava console to work. While it works, it has two problems (1) it does not open a graphics display, so you could not see the plots you were making (But plots are still generated and included into Sweave documents) and (2) it would drop out if there were any errors in the R code, causing you to have to start over.

The trick with getting RJava to work is set the configuration in the JRE tab in eclipse. In the VM Arguments, there should be an option included that points to rJava (which you have installed and run
sudo R CMD javareconf
to enable)

-Drjava.path=/path.to/rJava

(where the /path.to/ is your path to the location you installed your rJava library in the R directory. On my system it is /home/my_account/R/i486-pc-linux-gnu-library/2.9/ )

This provides a stable interactive R console and allows Sweave.

For Python, in addition to the standard interpreters (python, jython, ipy), you can run Sage. This would be through using the Python interpreter that is in the Sage package.

So add another Python interprester pointing to /sage-4.x.x/bin/python
With $SAGE_ROOT = /path/to/sage-4.x.x
and LD_LIBRARY_PATH = $SAGE_ROOT/local/lib

Next steps, figure out how to add R libraries to the R included in Sage, so R packages can be called from within Sage (note that R can be called using the rpy2 package, but this is only the currently installed packages.)

4 comments:

lugerpitt said...

Another note: To install a package into the Sage local packages
sage -python /local/bin/easy_install packagename

G said...

Dear Sir,

Your notes on setting up sage w/ Eclipse have been very helpful. I'm currently trying to use "R" from within Sage in Eclipse, but I just cannot get it to work.

You mentioned that you were looking into ways to access sage's R libraries from Eclipse and I was wondering if you had any success? I'd appreciate any help.

My aim is to be able to use all of Sage's inbuilt facilities (Esp. R), but to do so in an actual IDE, rather than the notebook or shell.

Thanks!
G

lugerpitt said...

I have not really followed up this, since I tend to use Sage from the notebook environment (mostly as a teaching exercise or developmental tool, then I go back to Python for implementations)

For R, 1st issue is to install the library using the R that is packaged in Sage. After that, look at the rpy2 documentation (URL below). The key issue is understanding how the library functions will be named since the '.' denotes a class member in Python. I suspect that you would need to do a bit of experimenting with the library in question.

http://rpy.sourceforge.net/rpy2/doc-2.2/html/porting-to-rpy2.html

G said...

I was hoping to use R "natively" like you can in Sage, for example:

sage: x=r([1,2,3,4,5,6)]
sage: r.summary(x)

is essentially executing R from sage, without Rpy/2 wrapper. It is this functionality I was trying to figure how to use from Eclipse

Thanks!

G