Re: [Rd] R_tryEval for OCaml-R.

From: Guillaume Yziquel <>
Date: Sat, 14 Nov 2009 23:52:03 +0100

Dirk Eddelbuettel a écrit :
> On 14 November 2009 at 16:45, Guillaume Yziquel wrote:
> | I've had a look at R-exts.pdf, but R_tryEval is not documented.
> |
> | Could someone please point me to relevant documentation,
> I don't think it is documented as it is not part of the API -- see for
> example R's src/main/context.c where you find
> R_tryEval is in Rinternals.h (so public), but not in the API.

Thanks for your help, Dirk and Romain.

I've gathered that 'eval' and R_tryEval are roughly equivalent, except that R_tryEval has error checking mechanisms. Please correct me if I'm wrong.

Here's the code I've been writing:

> yziquel_at_seldon:~/sandbox/ocaml-r/src$ grep -A 16 r_eval_sexp_list r_base.c
> CAMLprim value r_eval_sexp_list (value sexp_list) {
> CAMLparam1(sexp_list);
> SEXP sexp2eval = (SEXP) Long_val(Field(sexp_list,0));
> SEXP e;
> int error = 0;
> /* Should this be wrapped with a PROTECT() and
> an UNPROTECT(1)? */
> e = R_tryEval(sexp2eval, R_GlobalEnv, &error);
> if (error) {caml_failwith(
> "OCaml-R error in eval_sexp_list C stub."
> );};

> CAMLreturn(Val_sexp(e));
> }

> yziquel_at_seldon:~/sandbox/ocaml-r/src$

Can be found over there:

It seems to me that I should be wrapping the call to R_tryEval with a PROTECT(). Not too sure where to put the UNPROTECT(1) for now.

I've however been looking more closely at

and more specifically at the function lapply2 and the piece of code just afterwards, from src/main/print.c. I'm therefore wondering what should the first argument of the LISTSXP be. In lapply2, it seems that it's an R function per se, whereas in the code from src/main/print.c, it seems that it's more a symbol.

There's very probably something obvious that I do not yet get.

What I'd like, is my r_eval_sexp_list to be pure SEXPs. Not symbols. I want to transparently move SEXPs from R to OCaml, and backwards. So ideally, the first element of the LISTSXP would be a function and nothing else.

So my question: what exactly is the first element of the LISTSXP supposed to be?

Please tell me if I'm going offtrack here.

All the best,

      Guillaume Yziquel

______________________________________________ mailing list
Received on Sat 14 Nov 2009 - 22:54:40 GMT

This archive was generated by hypermail 2.2.0 : Sun 29 Nov 2009 - 00:30:50 GMT