2

A Session is Renjin is not thread safe as described here, but is it reentrant safe ?

The scenario is calling from java engine.eval("...") that has a Java class that calls again the same engine.eval("..") method. Let's assume we've only one engine instance for the sake of simplicity.

ic3
  • 7,917
  • 14
  • 67
  • 115

1 Answers1

2

Yes, that is possible.

Note that by calling engine.eval() on the original ScriptEngine instance, the expression will be evaluated in the global environment and the R function won't be able to see the R call stack that invoked the Java method.

You can also ask Renjin to pass the current Context to your Java method when invoked. For example:

class MyJavaClass {
   static SEXP estimate(@Current Context context, SEXP function) {
      return context.evaluate(FunctionCall.newCall(function, IntVector.valueOf(42)));
   }
}

And then:

import(MyJavaClass)
f <- function(x) x*2
MyJavaClass$estimate(f)  # 84
akbertram
  • 1,330
  • 10
  • 16
  • That's really nice, the issue is having R calling 'our engine' that in his query has R code. It's statelss from the context point of view. – ic3 Apr 20 '17 at 12:39