使用 Renjin 从 Scala 中的 R 脚本加载 .RData
Load .RData from an R script in Scala using Renjin
我有一个 R 脚本 load.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 应用程序中处理一些数据。
阅读 documention 上的数据部分没有提到从 .RData
文件加载数据。
更新:
在我的 build.sbt
文件中我有:
resolvers += "BeDataDriven" at https://nexus.bedatadriven.com/content/groups/public",
libraryDependencies += "org.renjin" % "renjin-script-engine" % "0.8.1886"
仅在类路径中包含 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
问题是coursier
无法解决所有依赖项(没有任何通知)。
从 plugins.sbt
中删除 addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15")
并使用 sbt 的默认解析器解决了这个问题。
我有一个 R 脚本 load.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 应用程序中处理一些数据。
阅读 documention 上的数据部分没有提到从 .RData
文件加载数据。
更新:
在我的 build.sbt
文件中我有:
resolvers += "BeDataDriven" at https://nexus.bedatadriven.com/content/groups/public",
libraryDependencies += "org.renjin" % "renjin-script-engine" % "0.8.1886"
仅在类路径中包含 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
问题是coursier
无法解决所有依赖项(没有任何通知)。
从 plugins.sbt
中删除 addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15")
并使用 sbt 的默认解析器解决了这个问题。