1

我有一个load.R尝试做的 R 脚本

load("test.RData")

当我运行时:

engine.eval(new FileReader("load.R"))

出现异常:

   Exception in thread "main" java.lang.NoClassDefFoundError: org/tukaani/xz/XZInputStream
    at org.renjin.primitives.io.connections.Connections.gzfile(Connections.java:79)
    at org.renjin.primitives.R$primitive$gzfile.doApply(R$primitive$gzfile.java:75)
    at org.renjin.primitives.R$primitive$gzfile.apply(R$primitive$gzfile.java:36)
    at org.renjin.primitives.special.InternalFunction.apply(InternalFunction.java:45)
    at org.renjin.eval.Context.evaluateCall(Context.java:302)
    at org.renjin.eval.Context.evaluate(Context.java:222)
    at org.renjin.eval.Context.evaluate(Context.java:163)
    at org.renjin.sexp.Closure.doApply(Closure.java:83)
    at org.renjin.eval.ClosureDispatcher.apply(ClosureDispatcher.java:73)
    at org.renjin.eval.ClosureDispatcher.applyClosure(ClosureDispatcher.java:58)
    at org.renjin.sexp.Closure.apply(Closure.java:78)
    at org.renjin.eval.Context.evaluateCall(Context.java:302)
    at org.renjin.eval.Context.evaluate(Context.java:222)
    at org.renjin.primitives.special.AssignLeftFunction.assignLeft(AssignLeftFunction.java:57)
    at org.renjin.primitives.special.AssignLeftFunction.apply(AssignLeftFunction.java:41)
    at org.renjin.eval.Context.evaluateCall(Context.java:302)
    at org.renjin.eval.Context.evaluate(Context.java:222)
    at org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:38)
    at org.renjin.eval.Context.evaluateCall(Context.java:302)
    at org.renjin.eval.Context.evaluate(Context.java:222)
    at org.renjin.primitives.special.IfFunction.apply(IfFunction.java:40)
    at org.renjin.eval.Context.evaluateCall(Context.java:302)
    at org.renjin.eval.Context.evaluate(Context.java:222)
    at org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:38)
    at org.renjin.eval.Context.evaluateCall(Context.java:302)
    at org.renjin.eval.Context.evaluate(Context.java:222)
    at org.renjin.eval.Context.evaluate(Context.java:163)
    at org.renjin.sexp.Closure.doApply(Closure.java:83)
    at org.renjin.eval.ClosureDispatcher.apply(ClosureDispatcher.java:73)
    at org.renjin.eval.ClosureDispatcher.applyClosure(ClosureDispatcher.java:58)
    at org.renjin.sexp.Closure.apply(Closure.java:78)
    at org.renjin.eval.Context.evaluateCall(Context.java:302)
    at org.renjin.eval.Context.evaluate(Context.java:222)
    at org.renjin.eval.Context.evaluateExpressionVector(Context.java:285)
    at org.renjin.eval.Context.evaluate(Context.java:220)
    at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:145)
    at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:104)
    at com.infosistema.imp.restservice.data_treatment.DataTreatment.<init>(DataTreatment.scala:34)
    at com.infosistema.imp.restservice.data_treatment.Main$.<init>(DataTreatment.scala:45)
    at com.infosistema.imp.restservice.data_treatment.Main$.<clinit>(DataTreatment.scala)
    at com.infosistema.imp.restservice.data_treatment.Main.main(DataTreatment.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.tukaani.xz.XZInputStream
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 46 more

我不知道 R。我只是尝试使用 R 代码在使用 Renjin 的 Java/Scala 应用程序中处理一些数据。

阅读文档上的数据部分,没有提到从.RData文件中加载数据。

更新: 在我的build.sbt文件中,我有:

resolvers += "BeDataDriven" at https://nexus.bedatadriven.com/content/groups/public",
libraryDependencies += "org.renjin" % "renjin-script-engine" % "0.8.1886"
4

2 回答 2

1

仅在类路径中有 renjin-script-engine.jar 是不够的,您还需要它的依赖项。

如果您使用 SBT 构建您的 Scala 项目,那么您需要将以下内容添加到您的构建文件中:

resolvers +=
  "BeDataDriven" at "https://nexus.bedatadriven.com/content/groups/public"

lazy val root = (project in file(".")).
  settings(
    name := "renjin-test",
    version := "1.0",
    scalaVersion := "2.10.6",
    libraryDependencies += "org.renjin" % "renjin-script-engine" % "0.8.1886"
)

对于其他构建工具,请参见: http ://docs.renjin.org/en/latest/library/project-setup.html

于 2016-12-01T16:31:40.083 回答
0

问题是coursier无法解决所有依赖项(没有任何通知)。

移除addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15")plugins.sbt使用 sbt 的默认解析器解决了这个问题。

于 2016-12-06T15:37:18.500 回答