[graalvm-users] Integration Ruby x R

Chris Seaton chris.seaton at oracle.com
Fri May 11 13:17:34 PDT 2018


I guess your R.eval definition looks something like this?

  module R
    def self.eval(string)
      Polyglot.eval("R", string)
    end
  end

1) I don’t know anything about R personally, but running the standard version of R and experimenting, it looks like it does return the value.

  > x = print(4)
  [1] 4
  > x
  [1] 4

2) Does R have a way to ask values what type they are? If so you can call that from interop.

  module 
    def self.typeof(object)
      eval("typeof").call(object)
    end
  end

  ...

  p R.typeof(val)

3) That’s something you could debate, but it looks like this is a specific design decision on the part of FastR, so it isn’t a mistake but you could open an issue with them if you think it’s wrong.

https://github.com/oracle/fastr/blob/acc680f0d1168aa42d19174130f67c40ccc811b6/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/interop/R2Foreign.java#L70-L73

> On 11 May 2018, at 21:05, Oleg Šelajev <oleg.selajev at oracle.com> wrote:
> 
> ---------- Forwarded message ----------
> From: Rodrigo Botafogo <rodrigo.a.botafogo at gmail.com>
> Date: 11 May 2018 22:11
> Subject: [graalvm-users] Integration Ruby x R
> To: graalvm-users at oss.oracle.com
> Cc: 
> 
> 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 element? 
> 
> Thanks
> 
> 
> 
> -- 
> Rodrigo Botafogo
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20180511/851cf769/attachment.html 


More information about the GraalVM-Users mailing list