[R] Usage of OCaml/R binding.

Guillaume Yziquel guillaume.yziquel at citycable.ch
Mon Sep 7 11:31:59 CEST 2009


Hello.

I've been pulling together a Debian package out of Maxence Guesdon's 
OCaml bindings for R. Will be available from my website as soon as I get 
my router to obey me. Here's Maxence's bindings:

	http://pauillac.inria.fr/~guesdon/ocaml-r.en.html

The purpose of this software is to access R from OCaml programs.

However, my issue is that after having pulled things to a Debian 
package, I am completely unfamiliar with the API, and I'm having trouble 
initialising this module.

You'll find below a list of the functions accessible from Maxence 
Guesdon's R module (there's also a Rmath module for the math library 
which I'm not yet concerned about).

I'd specifically appreciate information on how to get started using 
these R API functions. If you're scared about OCaml, simply look at the 
two declarations below in the following way:

	external init_r : string array -> int = "init_r"

'external' means that this value is to be fetched by linking C code 
identified by the '= "init_r"' ending statement. Typically, 'external' 
values wrap the API functions. So this value is called init_r, and takes 
an array of strings as first argument, and yields back an integer.

	val init : ?argv:string array -> unit -> int

'val' means that it is a standard OCaml value. It's called init. And its 
type is 'I take an array of strings as first argument, then a unit ( 
think of it a C void value containing nothing), and I get back an 
integer. The '?argv:' stuff is concerned with optional arguments, so no 
real big deal.

Documentation and examples of how the API works to embed R in an 
application would be highly appreciated. Please forward this email to 
R-dev if you feel it belongs there.

All the best,

Guillaume Yziquel.

> yziquel at seldon:~/sandbox/repo/debian/debian-ocaml/ocaml-r$ ocaml-batteries 
>         Objective Caml version 3.11.1
> 
>       _________________________________
>      |       | |                       |
>     [| +     | | Batteries Included  - |
>      |_______|_|_______________________|
>       _________________________________
>      |                       | |       |
>      | -    Type '#help;;'   | |     + |]
>      |_______________________|_|_______|
> 
> 
> # #rectypes;;
> # #require "R";;
> # module X = R;;
> module X :
>   sig
>     external init_r : string array -> int = "init_r"
>     val init : ?argv:string array -> unit -> int
>     external terminate : unit -> unit = "end_r"
>     type sexp = R.sexp
>     type symbol = string
>     type arg = [ `Anon of sexp | `Named of sexp * symbol ]
>     external sexp : string -> sexp = "r_sexp_of_string"
>     external sexp_of_symbol : symbol -> sexp = "r_sexp_of_symbol"
>     external set_var : symbol -> sexp -> unit = "r_set_var"
>     external r_print_value : sexp -> unit = "r_print_value"
>     external exec : string -> arg array -> unit = "r_exec"
>     external current_test : unit -> unit = "r_current_test"
>     external to_bool : sexp -> bool = "bool_of_sexp"
>     external to_int : sexp -> int = "int_of_sexp"
>     external to_float : sexp -> float = "float_of_sexp"
>     external to_string : sexp -> string = "string_of_sexp"
>     external of_bool : bool -> sexp = "sexp_of_bool"
>     external of_int : int -> sexp = "sexp_of_int"
>     external of_float : float -> sexp = "sexp_of_float"
>     external of_string : string -> sexp = "sexp_of_string"
>     external to_bool_array : sexp -> bool array = "bool_array_of_sexp"
>     external to_int_array : sexp -> int array = "int_array_of_sexp"
>     external to_float_array : sexp -> float array = "float_array_of_sexp"
>     external to_string_array : sexp -> string array = "string_array_of_sexp"
>     external of_bool_array : bool array -> sexp = "sexp_of_bool_array"
>     external of_int_array : int array -> sexp = "sexp_of_int_array"
>     external of_float_array : float array -> sexp = "sexp_of_float_array"
>     external of_string_array : string array -> sexp = "sexp_of_string_array"
>     external get_attrib : sexp -> string -> sexp = "r_get_attrib"
>     val dim : sexp -> int array
>     val dimnames : sexp -> string array
>   end
> # 


-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/




More information about the R-help mailing list