Skip to content

R_tryEval for OCaml-R.

5 messages · Dirk Eddelbuettel, Romain Francois, Guillaume Yziquel

#
Hello.

I'm currently working on the OCaml-R binding allowing to call R code 
from Objective Caml.

As Objective Caml is a functional language, I'd like the binding to be 
as 'functional' as possible. Specifically, this means that I'd like 
using the R_tryEval function and all related entry points in libR.so.

I've had a look at R-exts.pdf, but R_tryEval is not documented.

Could someone please point me to relevant documentation, or the relevant 
part of the R source code?

All the best,
#
On 14 November 2009 at 16:45, Guillaume Yziquel wrote:
| I'm currently working on the OCaml-R binding allowing to call R code 
| from Objective Caml.
| 
| As Objective Caml is a functional language, I'd like the binding to be 
| as 'functional' as possible. Specifically, this means that I'd like 
| using the R_tryEval function and all related entry points in libR.so.
| 
| 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.

That doesn't stop several projects from using it but we know it can break.

| or the relevant part of the R source code?

Besides the usual recursive grep 

   edd at ron:~$ grep -rinl R_tryEval /home/edd/src/debian/R/R-2.10.0/
   /home/edd/src/debian/R/R-2.10.0/ONEWS
   /home/edd/src/debian/R/R-2.10.0/src/library/methods/src/methods_list_dispatch.c
   /home/edd/src/debian/R/R-2.10.0/src/main/main.c
   /home/edd/src/debian/R/R-2.10.0/src/main/context.c
   /home/edd/src/debian/R/R-2.10.0/src/include/Rinternals.h
   /home/edd/src/debian/R/R-2.10.0/tests/Embedding/Rpackage.c
   /home/edd/src/debian/R/R-2.10.0/tests/Embedding/Rshutdown.c
   /home/edd/src/debian/R/R-2.10.0/tests/Embedding/embeddedRCall.c
   /home/edd/src/debian/R/R-2.10.0/tests/Embedding/RParseEval.c
   /home/edd/src/debian/R/R-2.10.0/tests/Embedding/RNamedCall.c
   /home/edd/src/debian/R/R-2.10.0/tests/Embedding/Rerror.c
   /home/edd/src/debian/R/R-2.10.0/tests/Embedding/tryEval.c
   edd at ron:~$

you can always try Google Code Search as in 

   http://www.google.com/codesearch?q=R_tryEval&hl=en&btnG=Search+Code

Hth, Dirk
#
You can also see it in action in jri (in the Rengine.c file). 
http://www.rforge.net/JRI/

Romain
On 11/14/2009 05:24 PM, Dirk Eddelbuettel wrote:

  
    
#
Dirk Eddelbuettel a ?crit :
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:
Can be found over there:

http://svn.gna.org/viewcvs/ocaml-r/trunk/src/r_base.c?rev=45&view=markup

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

http://cran.r-project.org/doc/manuals/R-exts.html#Evaluating-R-expressions-from-C

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,