Using Renjin packages inside a R file run by @ScriptManager

I am trying to use csvread and ggplot inside a R script but am getting the following error:

org.renjin.eval.EvalException: Could not load package org.renjin.cran:csvread; tried org.renjin.cran:csvread, org.renjin.bioconductor:org.renjin.cran:csvread, org.renjin.cran:org.renjin.cran:csvread

I am loading the appropriate dependencies inside the pom.xml:


@k3no, maybe I can help. I’ve been working through Renjin for a project of mine for the past month or so. At first, I was able to get Renjin and ggplot2 to work within ImageJ as a process generated by an IDE but not from vanilla ImageJ/FIJI. I believe this is because 1) maven in the IDE solves all the dependencies (ggplot has a handful) and 2) from the IDE it was easy to switch to Renjin v3.5b76.

To get my plugin to run in vanilla FIJI, I had to 1) replace the Renjin that shipped with FIJI (v3.5b76, listed below) and 2) provide the Renjin package jars(wrapped R libraries) with their dependencies that I wanted to use-by providing an uber jar. I’m not crazy about uber jars-in this case shaded-but it is working.

For reference, the Renjin files that come with FIJI I replaced/added:


I’ve asked on the forum about getting the version updated in SciJava, so eventually this shouldnt be necessary!

Cheers. Seth

Could you send me your working version of FIJI?
That would be super helpful.

Yes, let me package it up. Going to put a pull request in for upgrading Renjin too-just haven’t gotten to it. I’ll email you momentarily.


1 Like

For your interest, here’s a pull request upgrading the Renjin version in Fiji to 3.5-beta76:

Would you be willing to share a minimal example of how you used ggplot2 together with Renjin? Maybe this is something we can include as an example in the script templates?

Did you save the plot as file? Or are there any means to transfer the plot object back to a Java image?

1 Like

Thank you so much for assembling the PR. It was at end of a very long list… Did you address package loading? This was one my stumbling points. As far as I could tell the Renjin derived jars for R packages and their dependencies need to be included too. I suppose we could include a subset of common packages.

I’d be happy to draft an example of how to use it, focusing on plotting with ggplot or pheatmap.2 and maybe some light machine learning/clustering although I prefer SMILE( as a pure Java solution. I’ve been using Renjin programmatically, but can look at the R scripts that are already in the scripting templates for guidance.

Passing objects is possible with Renjin, I opted to use a file intermediate for plots and Java drawing an image in a container. This makes exporting well rastered plots kind of cludgy. It also feels a little like cheating but this approach got me to the solution in the time I had.

Data.frames from R are simpler, so maybe I could put together a clustering example to do something like take a resultstable from imagej, cluster by the columns return a new column with the classes and repopulate the results table? It would be easier with SMILE, but could be a useful approach for harder to find implementations often in R.

Thanks again for working out the pull request.