R scripting - current and future directions

After learning about Bio7 I decided to try and finish the ImageJ R scripting support.

Basic functionality is basically complete (ImageJ executing R code using Rserve) but I am looking for feedback on more advanced topics:

  • I haven’t found a good way to call methods on Java objects from inside R. There is a Java wrapping REXP but it doesn’t seem to be supported in the standard REngine (a RConnection, for connecting to your running Rserve). There is a JRIEngine which sounds promising - but I haven’t been able to find a Maven artifact that distributes it, to test… :frowning:

  • Without the ability to directly access Java code in R, I can still create Converters between ImageJ and R objects. I would likely make this identical to the MATLAB support, converting between images/datasets and R arrays to allow easy statistical analysis of the pixels. Are there other converters that people would like to see?

  • I would also like to use Bio7 as a driving case for external consumption here. I envision an ideal scenario where Bio7 has a dependency on scripting-r and uses RScriptEngine.eval to make requests to R. I can definitely start a branch to work on this, but @Bio7 can you point me to places where you’re manually converting between Java and R structures, and where you’re calling into Rserve?

  • There are a couple things that still bother me about R use with Rserve - users have to independently install R, and manually start their own server. We can add an Options dialog to allow remote Rserve connections but I assume that will help a minority of cases. Does anyone know of other ways to distribute R or at least instruct R to launch from Java with the desired libraries loaded?

1 Like

That sounds promising!

What about:

<dependency>
  <groupId>com.github.lucarosellini.rJava</groupId>
  <artifactId>JRIEngine</artifactId>
  <version>0.9-7</version>
</dependency>

(from maven.imagej.net) ?

Converting ResultsTables (or their ImageJ2 equivalent) to R objects would be useful, I guess.

Dear Marc,

have a look at:

https://github.com/Bio7/bio7_examples/blob/master/ImageJ_Conference_2012/Rserve_Example/Rserve_Example.java

and the other simple R engine examples I created for ImageJ image data.

https://github.com/Bio7/bio7_examples/tree/master/ImageJ_Conference_2012

The image data (in this example) is transferred and a matrix object is created within R.

To start R from within Java please have a look at the Rserve example and the other examples Java data to R from Simon Urbanek:

Here is a JRI example:

In Bio7 R is started from within a self created custom Java pseudo OS terminal and then I pipe the command to start Rserve from within R. I can switch forth and back between a native R connection (shutdown Rserve) and the Rserve connection without the lost of R workspace data (Rserve cooperative mode - as a kind of desktop connection).

It is also possible to connect Bio7 to a remote R instance and with multiple Rserve connections and it is also possible to create calculations in a cluster with Rserve (a possible future perspective).

https://rforge.net/Rserve.cluster/

1 Like

2 posts were split to a new topic: Problem running Renjin script