[graalvm-users] Integration Ruby x R

Rodrigo Botafogo rodrigo.a.botafogo at gmail.com
Fri May 11 12:11:07 PDT 2018

Hello Graalers...

I'm trying to test and implement an integration between Ruby and R.  For
that I have implemented this simple code where R.eval is a call to the R
eval function.

    p R.eval("var = 4")
    p R.eval("print(var)")
    val = R.eval("var = 4")
    p val
    val = R.eval("var = c(1, 2, 3, 4)")
    p val
    p val[1]
    val = R.eval("list(1, 2, c('a', 'b', 'c'))")
    p val
    p val[2][1]

I get the following results for this code:

4.0           # result of R.eval("var = 4")
[1] 4         # the print(var) in R
4.0           # result of R.eval("print(var)")
4.0           # p val
#<Truffle::Interop::Foreign at 46994f26>  # pointer to the c(1, 2, 3, 4) op
2.0           # p val[1]
#<Truffle::Interop::Foreign at 2b8cf049>  # pointer to the list
"b"           # p val[2][1]

My questions:

1) In R, if I'm not mistaken print(var) has no return value.  Should we get
4.0 as return in this case?
2) The first pointer a foreign object points to a vector while the second
pointer points to a list.  In this simple case, we know beforehand the type
of the object, but in general this might not be true.  Is there any way to
know the type of the object and to what messages it responds?  This seems
critical to me to be able to really integrate both languages;
3) The result of R.eval("var = 4") in R is a vector, but we get back a
float in Ruby.  For consistency, shouldn't this be a Ruby vector with 1


Rodrigo Botafogo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20180511/644461ea/attachment.html 

More information about the GraalVM-Users mailing list