2

I want to load & parse RDS/RData files in Java, i've made some googling and found that Renjin helps calling R functions in Java. (i'm not a R developer and i didn't even know the existance of these files before ^^')

so this is my R code :

my_data <- readRDS("R/outputs_profils_cl8.RDS")

and this is my Java code :

RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
RenjinScriptEngine engine = factory.getScriptEngine();
        
engine.eval(new java.io.FileReader("R/script.R"));

my pom.xml file :

<dependency>
        <groupId>org.renjin</groupId>
        <artifactId>renjin-script-engine</artifactId>
        <version>3.5-beta65</version>
    </dependency>

But i got this error :

Exception in thread "main" org.renjin.eval.EvalException: cannot read workspace version 3 written by R 3.5.0; need R 3.5.0 or newer at org.renjin.primitives.R$primitive$unserializeFromConn.applyPromised(R$primitive$unserializeFromConn.java:42) at org.renjin.sexp.BuiltinFunction.apply(BuiltinFunction.java:100) at org.renjin.primitives.special.InternalFunction.apply(InternalFunction.java:46) at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:39) at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at org.renjin.sexp.Closure.applyPromised(Closure.java:200) at org.renjin.sexp.Closure.apply(Closure.java:133) at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at org.renjin.primitives.special.AssignLeftFunction.assignLeft(AssignLeftFunction.java:58) at org.renjin.primitives.special.AssignLeftFunction.apply(AssignLeftFunction.java:42) at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80) at org.renjin.sexp.ExpressionVector.eval(ExpressionVector.java:85) at org.renjin.eval.Context.evaluate(Context.java:280) at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:174) at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:169) at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:148) at control.Main.main(Main.java:330)

do you have any idea how to solve this problem ? i've followed installation instructions from Renjin website.

and I remain open if you can propose any other solution/library that can do the work :)

Thanks for advance !

1 Answers1

0

While I am sure there are ways to do this, I think you should ask yourself if you should.

.RData is not a conventional format to store and transfer files between different software. Instead, you should export your data from the .Rdata files to a more suitable format, for example comma-separated values (.csv).

These others formats have much wider support, and will be much more suited in most cases.

mhovd
  • 3,724
  • 2
  • 21
  • 47