gordon.j.miller / gmail.com wrote:
> Have you thought about simply spawning an inferior process and simply
> pass R scripts into the process?  This is basically what emacs does
> with their ESS mode and it works wonderfully well.  Depending on the
> level of integration that you wanted to achieve between R and Ruby this
> could work very well.  I'm not sure how well suited the R system is to
> be treated as a library, though I'll confess I haven't really looked
> into it.
>   
The "guts" of how to interface R with C, C++ and Fortran, and how to
build R as a shared library and call it from the "outside world" are
documented in the "Writing R Extensions" manual that comes with the
source (or the Windows installer). I took the course up at Fred
Hutchinson Cancer Research Center in January and we covered this in a
fair amount of detail. The sample code is on line at

http://www.bioconductor.org/workshops/2006/rforbioinformatics/

If you want to do any of this magic on Windows, be prepared to download
a lot of tools and be prepared to put aside your creative urges and just
follow directions to the letter. :)

I have never used "RSPerl"; I usually call R scripts from Perl via

    system("R < script.R");

passing parameters as environment variables -- Perl exports them and R
imports them.
> If one were to simply use an inferior process that you passed straight
> R scripts into you could write a set of functions to translate between
> Ruby and R speak (array notation, using <- instead of =, parsing
> through the response from R to set a global hash of R variables, etc).
>   
"=" works in R now as an assignment operator. I'm not sure when that
happened; I've gotten into the habit of "<-" and probably don't intend
to switch. ;)
> I'd be willing to contribute and test stuff as I use R quite a bit for
> data analysis.  Its a very, very good language for doing mathematics,
> statistics, and modelling that I don't want to redo in Ruby.  Not that
> I couldn't I just don't want to repeat the effort.  The biggest problem
> is R has a huge lack of string processing features that make setting up
> model runs and generating reports that Ruby is quite good at.
>   
R isn't as bad at "scripting" and "regular expression handling" as all
that. It ain't Perl and it ain't Ruby, and if you're at all an
object-oriented programmer, you'll find the way R does objects and
classes totally different from the "real world". Then again, so is the
way Perl does it -- Ruby is a lot more like a "real object-oriented
language."

Of course, when I first started using R, it really sucked at the
character handling, and I wrote a lot of Perl making "CSV" files for R
to handle. Nowadays I just load things into a database and let RODBC do
all the work. :)

I'm sorta kinda looking at a project that would use *Rails* to manage
the database(s), shelling out to "R" for the analysis. I've got very
little lead time, though, so it might have to be just a refactoring of
the hundreds of lines of Perl and R I have now. And I don't have any
Ruby-aware cow-orkers ... that's a risk too.

-- 
M. Edward (Ed) Borasky

http://linuxcapacityplanning.com