bedatadriven / renjin

JVM-based interpreter for the R language for the statistical analysis.
https://www.renjin.org
GNU General Public License v2.0
514 stars 82 forks source link

Renijin sample fails if module-info.java is used #471

Open tomprodehl opened 5 years ago

tomprodehl commented 5 years ago

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 renjin.core@3.5-beta64/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:181)
    at renjin.script.engine@3.5-beta64/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 renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:154)
    at renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:130)
    at renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:114)
    at renjin.core@3.5-beta64/org.renjin.primitives.packaging.Packages.library(Packages.java:39)
    at renjin.core@3.5-beta64/org.renjin.primitives.R$primitive$library.doApply(R$primitive$library.java:68)
    at renjin.core@3.5-beta64/org.renjin.primitives.R$primitive$library.applyPromised(R$primitive$library.java:33)
    at renjin.core@3.5-beta64/org.renjin.sexp.BuiltinFunction.apply(BuiltinFunction.java:100)
    at renjin.core@3.5-beta64/org.renjin.primitives.special.InternalFunction.apply(InternalFunction.java:46)
    at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at renjin.core@3.5-beta64/org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:39)
    at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at renjin.core@3.5-beta64/org.renjin.sexp.Closure.applyPromised(Closure.java:200)
    at renjin.core@3.5-beta64/org.renjin.sexp.Closure.apply(Closure.java:133)
    at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at renjin.core@3.5-beta64/org.renjin.eval.Context.evaluate(Context.java:280)
    at renjin.core@3.5-beta64/org.renjin.eval.Context.evaluate(Context.java:209)
    at renjin.core@3.5-beta64/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:176)
    ... 2 more
akbertram commented 5 years ago

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 notifications@github.com 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 renjin.core@3.5-beta64/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:181) at renjin.script.engine@3.5-beta64/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 renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:154) at renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:130) at renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:114) at renjin.core@3.5-beta64/org.renjin.primitives.packaging.Packages.library(Packages.java:39) at renjin.core@3.5-beta64/org.renjin.primitives.R$primitive$library.doApply(R$primitive$library.java:68) at renjin.core@3.5-beta64/org.renjin.primitives.R$primitive$library.applyPromised(R$primitive$library.java:33) at renjin.core@3.5-beta64/org.renjin.sexp.BuiltinFunction.apply(BuiltinFunction.java:100) at renjin.core@3.5-beta64/org.renjin.primitives.special.InternalFunction.apply(InternalFunction.java:46) at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at renjin.core@3.5-beta64/org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:39) at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at renjin.core@3.5-beta64/org.renjin.sexp.Closure.applyPromised(Closure.java:200) at renjin.core@3.5-beta64/org.renjin.sexp.Closure.apply(Closure.java:133) at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at renjin.core@3.5-beta64/org.renjin.eval.Context.evaluate(Context.java:280) at renjin.core@3.5-beta64/org.renjin.eval.Context.evaluate(Context.java:209) at renjin.core@3.5-beta64/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 commented 5 years ago

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?