[R] embedding R?
John D. Barnett
jdb at young39.wi.mit.edu
Tue Feb 13 23:28:31 CET 2001
On Sun, 11 Feb 2001, Aaron J Mackey wrote:
> ... What about a program that
> dynamically loads R itself ...
I've been interested in this topic for a while, too, but haven't done much
with it yet. I saw some of the replies, pointing to omegahat, the
directions for embedding R.
Another shortcut to perl <-> R interactivity is to use the Expect perl
module (I think expect was originally in tcl), which is basically a fancy
bi-directional pipe. You're still faced with using perl to prepare R
input, and parse R output, but you can do so one call at a time. Also,
expect just waits until it sees the next prompt or times out (though the
time-out can be disabled). I tried to automatically convert R output into
perl data structures; this can be messy.
I'm interested in web application development that utilizes R. Duncan
Temple Lang's RSPerl package, embedding perl in R, lets you access great
perl modules, like CGI.pm; a hack to R lets it handle scripts like
foo <- .PerlExpr("use CGI;");
foo <- .PerlExpr("$q = new CGI; 1;");
a <- .PerlExpr("$q->param('a')");
cat(.PerlExpr("$q->header . $q->start_html . 'Hellooooo....';"),
Anyway, that's about all I did with it. (OK, maybe that's exactly what
I did; proof of concept and no more.) It has R functions for accessing
perl data structures, which might serve as a useful template for the
reverse process-- having perl functions to access R data structures, for R
embedded in perl. I'm a little fuzzy on what the appropriate mapping is
for different data types.
A random aside-- there's a package for perl, PDL (perl data language),
that stores data in C arrays, and has optimized code for
computation. This also provides methods for converting perl arrays to
and from pdl structures, as well as fast I/O routines for pdl
structures. The icing on the perl-with-embedded-R cake would be
conversion methods directly between R arrays and pdl arrays.
I'm interested if you decide to pursue this further.
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help