There has been some mail-list discussion on R. As proof-of-concept, I
cobbled together some code that leverages the RCL package to call R from
Maxima (see attached for rcl-maxima.max that calls rcl-maxima.lisp). It
requires ASDF, CFFI and RCL.
The RCL package includes functions: r:r for calling an R function with
arguments and returning a decoded object; r::r-parse-eval for parsing
and evaluating an R expression and returning a decoded object; r:r% for
calling an R function with arguments and returning an R pointer; and
r::r%-parse-eval for parsing and evaluating an R expression and
returning an R pointer.
I have written similar functions r(function_name,arg1,...),
r_parse_eval(string_expression), r%(function_name,arg1,...) and
r%_parse_eval(string_expression), respectively. Keywords can be passed
to R using the kw() function.
[RCL passes back a decoded object as a list of data and attributes.
Functions: r_attributes(rcl_obj) extracts the attributes as an
association list; r_attr(rcl_obj,attribute) gets a particular attribute;
r_get_name(rcl_obj,name) gets a named item from a named list;
r_to_matrix(rcl_obj) converts to a Maxima matrix; r%_make_matrix(obj)
converts an rcl_object or a Maxima matrix to an R matrix pointer.]
Kindly, Mark Clements.
For example:
(%i1) load("rcl-maxima.max");
; loading system definition from e:\usr\lib\sbcl\1.0.22\rcl\rcl.asd into
; #<PACKAGE "ASDF0">
; registering #<SYSTEM #1=#:RCL {25593371}> as #1#
; loading system definition from e:\usr\lib\sbcl\1.0.22\cffi\cffi.asd
into
; #<PACKAGE "ASDF0">
; registering #<SYSTEM CFFI {256EEDF9}> as CFFI
(%o1) rcl-maxima.max
(%i2) r("rep",[1,2,3],kw("each"),3)+1;
(%o2) [2, 2, 2, 3, 3, 3, 4, 4, 4]
(%i3) r_parse_eval("matrix(c(1,1,0,1),2,byrow=T)");
(%o3) [[1.0, 0.0, 1.0, 1.0], [[DIM, [2, 2]]]]
(%i4) temp:r_to_matrix(%);
[ 1.0 1.0 ]
(%o4) [ ]
[ 0.0 1.0 ]
(%i5) r("solve",r%_make_matrix(temp));
(%o5) [[1.0, 0.0, - 1.0, 1.0], [[DIM, [2, 2]]]]
(%i6) r("sum",r%(":",1,10000));
(%o6) 50005000
(%i7) temp2:r_parse_eval("list(a=1,b=2)");
(%o7) [[1.0, 2.0], [[NAMES, [a, b]]]]
(%i8) r_get_name(temp2,"a");
(%o8) 1.0
(%i9) block([x,mu,y,pred,fit,sefit],
x:makelist(i/100.0,i,0,100),
mu:map(exp,makelist(2+xi,xi,x)),
r("set.seed",1010105),
y:r("rpois",length(x),mu),
r%("<-","x",x),
r%("<-","y",y),
pred:r_parse_eval("predict(glm(y~x,family=poisson),se.fit=T)"),
fit:r_get_name(pred,"fit"),
sefit:r_get_name(pred,"se.fit"),
r("postscript",kw("file"),"temp.eps"),
r("plot",x,y,kw("type"),"n",kw("xlab"),"x",kw("ylab"),"Count"),
r("polygon",append(x,reverse(x)),
append(map(exp,fit-1.96*sefit),reverse(map(exp,fit+1.96*sefit))),
kw("col"),"grey",kw("border"),?nil),
r("points",x,y),
r("lines",x,mu,kw("col"),"red"),
r("lines",x,map(exp,fit)),
r_parse_eval("legend('topleft',legend=c('True mean','Predicted
mean','+95% CI'),lty=1,col=c('red','black','grey'),bty='n')"),
r%("dev.off"))$
(%i10) view_eps("temp.eps");
(%o10) true
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rcl-maxima.lisp
Type: application/octet-stream
Size: 2284 bytes
Desc: rcl-maxima.lisp
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20100329/b8661f92/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rcl-maxima.max
Type: application/octet-stream
Size: 2609 bytes
Desc: rcl-maxima.max
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20100329/b8661f92/attachment-0001.obj>