renjin icon indicating copy to clipboard operation
renjin copied to clipboard

Renijin sample fails if module-info.java is used

Open tomprodehl opened this issue 5 years ago • 2 comments

A project that contains only the Renjin sample works as advertised.

Until module-info.java is added, enabling modular java package management.

Then the ScriptEngine trips an exception. I am doing all this from within IntelliJ latest version. Any solution?

package tryrenjin;
import javax.script.ScriptEngine;
import org.renjin.script.*;


    public class TryRenjin {
        public static void main(String[] args) throws Exception {
            // create a script engine manager:
            RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
            // create a Renjin engine:
            ScriptEngine engine = factory.getScriptEngine();
            engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))");
            engine.eval("print(df)");
            engine.eval("print(lm(y ~ x, df))");
        }
    }

module-info.java

module tryrenjin {
    requires java.scripting;
    requires renjin.script.engine;
}

Without module-info, it works:

      x     y    
 [1,]  1    0.347
 [2,]  2    2.006
 [3,]  3    4.285
 [4,]  4    4.033
 [5,]  5    4.152
 [6,]  6    7.243
 [7,]  7    7.001
 [8,]  8    6.846
 [9,]  9    9.487
[10,] 10    9.328

Call:
lm(formula = y ~ x, data = df)

Coefficients:
(Intercept) x          
0.206       0.958     

with module-info,java this is produced

Exception in thread "main" java.lang.RuntimeException: org.renjin.eval.EvalException: Could not load package org.renjin:methods
    at [email protected]/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:181)
    at [email protected]/org.renjin.script.RenjinScriptEngineFactory.getScriptEngine(RenjinScriptEngineFactory.java:110)
    at tryrenjin/tryrenjin.TryRenjin.main(TryRenjin.java:13)
Caused by: org.renjin.eval.EvalException: Could not load package org.renjin:methods
    at [email protected]/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:154)
    at [email protected]/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:130)
    at [email protected]/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:114)
    at [email protected]/org.renjin.primitives.packaging.Packages.library(Packages.java:39)
    at [email protected]/org.renjin.primitives.R$primitive$library.doApply(R$primitive$library.java:68)
    at [email protected]/org.renjin.primitives.R$primitive$library.applyPromised(R$primitive$library.java:33)
    at [email protected]/org.renjin.sexp.BuiltinFunction.apply(BuiltinFunction.java:100)
    at [email protected]/org.renjin.primitives.special.InternalFunction.apply(InternalFunction.java:46)
    at [email protected]/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at [email protected]/org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:39)
    at [email protected]/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at [email protected]/org.renjin.sexp.Closure.applyPromised(Closure.java:200)
    at [email protected]/org.renjin.sexp.Closure.apply(Closure.java:133)
    at [email protected]/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at [email protected]/org.renjin.eval.Context.evaluate(Context.java:280)
    at [email protected]/org.renjin.eval.Context.evaluate(Context.java:209)
    at [email protected]/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:176)
    ... 2 more

tomprodehl avatar Aug 06 '19 20:08 tomprodehl

Oh boy, I'm not sure where to start with Java 9 modules.

I'm guessing that the javax.scripting and org.renjin.script packages have dependencies on other packages that can be statically determined, but packages like "methods", "stats" or any CRAN packages are loaded dynamically via reflection and probably need to handled specially.

On Tue, Aug 6, 2019, 10:23 PM tomprodehl [email protected] wrote:

A project that contains only the Renjin sample works as advertised.

Until module-info.java is added, enabling modular java package management.

Then the ScriptEngine trips an exception. I am doing all this from within IntelliJ latest version. Any solution? `` package tryrenjin; import javax.script.ScriptEngine; import org.renjin.script.*;

public class TryRenjin { public static void main(String[] args) throws Exception { // create a script engine manager: RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory(); // create a Renjin engine: ScriptEngine engine = factory.getScriptEngine(); engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))"); engine.eval("print(df)"); engine.eval("print(lm(y ~ x, df))"); } }

``

module-info.java

module tryrenjin { requires java.scripting; requires renjin.script.engine; }

Without module-info, it works:

  x     y

[1,] 1 0.347 [2,] 2 2.006 [3,] 3 4.285 [4,] 4 4.033 [5,] 5 4.152 [6,] 6 7.243 [7,] 7 7.001 [8,] 8 6.846 [9,] 9 9.487 [10,] 10 9.328

Call: lm(formula = y ~ x, data = df)

Coefficients: (Intercept) x 0.206 0.958

with module-info,java this is produced

Exception in thread "main" java.lang.RuntimeException: org.renjin.eval.EvalException: Could not load package org.renjin:methods at [email protected]/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:181) at [email protected]/org.renjin.script.RenjinScriptEngineFactory.getScriptEngine(RenjinScriptEngineFactory.java:110) at tryrenjin/tryrenjin.TryRenjin.main(TryRenjin.java:13) Caused by: org.renjin.eval.EvalException: Could not load package org.renjin:methods at [email protected]/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:154) at [email protected]/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:130) at [email protected]/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:114) at [email protected]/org.renjin.primitives.packaging.Packages.library(Packages.java:39) at [email protected]/org.renjin.primitives.R$primitive$library.doApply(R$primitive$library.java:68) at [email protected]/org.renjin.primitives.R$primitive$library.applyPromised(R$primitive$library.java:33) at [email protected]/org.renjin.sexp.BuiltinFunction.apply(BuiltinFunction.java:100) at [email protected]/org.renjin.primitives.special.InternalFunction.apply(InternalFunction.java:46) at [email protected]/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at [email protected]/org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:39) at [email protected]/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at [email protected]/org.renjin.sexp.Closure.applyPromised(Closure.java:200) at [email protected]/org.renjin.sexp.Closure.apply(Closure.java:133) at [email protected]/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at [email protected]/org.renjin.eval.Context.evaluate(Context.java:280) at [email protected]/org.renjin.eval.Context.evaluate(Context.java:209) at [email protected]/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:176) ... 2 more

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bedatadriven/renjin/issues/471?email_source=notifications&email_token=AADO5Q4ZMELO6DRRVR4X6UDQDHMSHA5CNFSM4IJZ5Y52YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HDXHVFQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AADO5Q4VDRZUARTDRRWLURTQDHMSHANCNFSM4IJZ5Y5Q .

akbertram avatar Aug 06 '19 20:08 akbertram

I see you asked this question on Stackoverflow as well. We weren't planning on adding support for Java 9 modules to the 3.5 release, but if you're interested in a Renjin Support Subscription we could discuss adding this to release.

Otherwise i think it should just be a matter of adding the right module-info.java files to packages to permit access via reflection, perhaps you could submit a pull request?

akbertram avatar Aug 16 '19 12:08 akbertram