Search code examples
javarstudiograalvmfastr

Is it possible to use GraalVM / FastR directly from RStudio?


I browsed some docs but it is not clear to me if it is possible to use FastR / GraalVM in RStudio instead of default GNU R implementation.

My goal would be to integrate R code and Java code in a much more friendly way than current solution which uses RJava and some wrapper functions to call java code.

This is one of the nice features that is advertised by GraalVM. An integration of Java and R code (in both directions )is explained here for instance https://medium.com/graalvm/enhance-your-java-spring-application-with-r-data-science-b669a8c28bea.


Solution

  • FastR used to have prototypical integration with RStudio and we are planning to revive this at some point, however, there is no concrete time frame for this yet.

    Update: FastR works well with this Visual Studio code plugin. You just need to set the path to FastR executable instead of GNU-R.

    More technical details: RStudio (rserver more precisely) uses R in the embedded mode, which is supported by FastR 1[2], but has not been tested with RStudio since we did the prototype in 2016. Additionally, RStudio uses R API to directly access R's execution contexts, which is hard to emulate for FastR since it is just bunch of C global variables. FastR provides functions to access the execution contexts[3][4] and RStudio needs to be patched to use those functions instead.

    1 https://github.com/oracle/fastr/blob/master/com.oracle.truffle.r.native/fficall/src/truffle_nfi/Rembedded.c

    [2] tests: https://github.com/oracle/fastr/tree/master/com.oracle.truffle.r.test.native/embedded

    [3] native side: https://github.com/oracle/fastr/blob/master/com.oracle.truffle.r.native/fficall/src/truffle_nfi/Rembedded.c#L262

    [4] Java side: https://github.com/oracle/fastr/blob/master/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/IDEUpCallsRFFI.java