Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] R bindings ?

0 views
Skip to first unread message

Maxence Guesdon

unread,
Mar 14, 2008, 7:32:56 AM3/14/08
to caml...@inria.fr
Hello,

Has anyone developed any kind of bindings with R-project to call R
from OCaml programs ? If so, is it available somewhere ?

Thanks,

Maxence Guesdon

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Ashish Agarwal

unread,
Mar 15, 2008, 8:40:37 AM3/15/08
to Maxence Guesdon, caml...@inria.fr
I searched a few weeks ago for this but did not find anything.


On Fri, Mar 14, 2008 at 7:32 AM, Maxence Guesdon <maxence...@inria.fr>
wrote:

Francois Rouaix

unread,
Mar 15, 2008, 12:09:12 PM3/15/08
to Ashish Agarwal, Maxence Guesdon, caml...@inria.fr
And why do you need bindings instead of simply feeding generated source code
to the R toplevel?Low-level bindings are mostly useful if the calls go both
ways or if the parsing costs represent a high overhead.
--f


2008/3/15 Ashish Agarwal <agarw...@gmail.com>:

Ashish Agarwal

unread,
Mar 15, 2008, 3:53:46 PM3/15/08
to Francois Rouaix, Maxence Guesdon, caml...@inria.fr
There would be high overhead because I would be passing very large data sets
back and forth. And I thought a binding would be easier to use.
Printing/parsing becomes tedious.


On Sat, Mar 15, 2008 at 12:08 PM, Francois Rouaix <francoi...@gmail.com>
wrote:

Maxence Guesdon

unread,
Mar 16, 2008, 3:02:01 PM3/16/08
to caml...@inria.fr
Francois Rouaix <francoi...@gmail.com> a ?it :

> And why do you need bindings instead of simply feeding generated source code
> to the R toplevel?Low-level bindings are mostly useful if the calls go both
> ways or if the parsing costs represent a high overhead.

Because
- Printf-ing the code is kind of heavy and error-prone,
- parsing the computed values is some work to handle correctly,
- the compiler can't tell me if I did something wrong so I get all the
errors at execution time.

Maxence

Bünzli Daniel

unread,
Mar 16, 2008, 5:24:14 PM3/16/08
to Maxence Guesdon, caml...@inria.fr

Le 16 mars 08 à 20:01, Maxence Guesdon a écrit :

> Because
> - Printf-ing the code is kind of heavy and error-prone,
> - parsing the computed values is some work to handle correctly,
> - the compiler can't tell me if I did something wrong so I get all
> the errors at execution time.

This need not be the case if you apply language embedding/meta-
programmation techniques (see for example [1]). You can even mask R
computations behind plain caml functional types.

I have an unpolished toy example that does this to program arithmetic
functions on regular ocaml types but that use scsh to actually compute
the result (no camlp4 or unsafe features required), I can forward it
to you if you are interested.

Here's an example of a polymorphic cube function, when you invoke
cubei or cubef the result will actually be computed by scsh. The
drawback is that you need to "write" the type your functions by hand
(cf argi argf reti retf).

open Mini
open Override
open Program

let cube_s = fun x -> x * x * x

let cubei_p = compile (argi (reti cube_s))
let cubef_p = compile (argf (retf cube_s))

let cubei : int -> int = as_fun cubei_p
let cubef : float -> float = as_fun cubef_p

However as Ashish pointed out the biggest problem are the data sets,
but it may be that you can keep them in R only with suitable types to
represent them in ocaml.

Best,

Daniel

[1]

article{967844,
author = {Conal Elliott and Sigbj\&\#248;rn Finne and Oege De Moor},
title = {Compiling embedded languages},
journal = {J. Funct. Program.},
volume = {13},
number = {3},
year = {2003},
issn = {0956-7968},
pages = {455--481},
doi = {http://dx.doi.org/10.1017/S0956796802004574},
publisher = {Cambridge University Press},
address = {New York, NY, USA},

0 new messages