Calling R from Ruby

M

M. Edward (Ed) Borasky

Edwin said:
You can already do a lot of what matlab does with ruby-gsl. There are
also a couple of gnuplot and plotutils bridges to make plotting easy.
(plotutils bridge is part of ruby-gsl)

For an R bridge I use a simple class that writes stuff to a script file
and then executes the script with R. It is far from perfect but doable.
But I would certainly welcome a better bridge.
Both Octave and SciLab are more or less "Matlab clones", if that's what
you want. Octave is open source. SciLab is "free as in beer" and may
have loosened their license a bit since I last looked.

A few years ago, I looked at a lot of open source math and graphics
packages for inclusion in a project. The candidates were Octave,
Xlisp-Stat, Perl Data Language (PerlDL or PDL) and R. When the smoke
cleared, I picked R, even though at the time I was primarily a Perl
programmer.

That project is still going strong today, as is R and its community. I
don't think XLisp-Stat has released anything since then, Octave is more
or less stagnant and I lost track of PerlDL -- it's still the package of
choice for things like astronomical image processing.
 
M

M. Edward (Ed) Borasky

Yeah ... in fact there is an R DCOM server and client in the CRAN
package repository for Windows. There's also an interesting package
called, IIRC, RExcel, which lets you call an R server inside an Excel
spreadsheet.
 
A

AlexG

Hi,

There is a version of my R embedding code at:

http://web.kuicr.kyoto-u.ac.jp/~alexg/files

This is very very rough and early. Think pre-pre-alpha. It is a
conversion of the core part of RSPerl allowing you to call R functions
from ruby scripts and pass simple data between them. Simple data means:
integers, floats and strings and arrays and hashes thereof. So you can
write:

require 'rsruby'
r=RSRuby.new #initialize embedded R interpreter
samples = 100
normal = r.rnorm(samples) #Calls R function 'rnorm'
puts normal #a Ruby array of floats converted from R vector
r.plot({ 'x' => normal, #You can call with named args
'xlab' => 'Hello Ruby',
'ylab' => 'Ruby ga suki desu'})
sleep(4) #Ooooh - pretty!

At this level it doesn't provide anything that Gordon/Ed's suggestion
of using an external R interpreter couldn't do. But perhaps with a bit
more work it might.

Anyway, if you're interested feel free to download and test. I've tried
it on a linux box and OSX, I have no idea how to build it under Windows
(or even if you could!). Documentation is essentially non-existent at
this stage, though there's a README which tells you how to build - you
just need to tell extconf.rb where your libR sits.

You can find my email address for bug reports/contributions in the
DESCRIPTION file.

Cheers,

AlexG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,204
Messages
2,571,066
Members
47,673
Latest member
MahaliaPal

Latest Threads

Top