R - Connecting R and java using Rserve -


i have build application connecting r , java using rserve package. in that, getting error "evaluation successful object big transport". have tried increasing send buffer size value in rconnection class also. doesn't seem work. object size being transported 4 mb

here code r connection file

public void setsendbuffersize(long sbs) throws rserveexception {

    if (!connected || rt == null) {         throw new rserveexception(this, "not connected");     }     try {         rpacket rp = rt.request(rtalk.cmd_setbuffersize, (int) sbs);         system.out.println("rp send buffer "+rp);         if (rp != null && rp.isok()) {             system.out.println("in if " + rp);             return;         }     } catch (exception e) {         e.printstacktrace();         logout.log.error("exception caught" + e);     }      //throw new rserveexception(this,"setsendbuffersize failed",rp);         } 

the full java class available here :rconnection.java

instead of rserve, can use jri, shipped rjava package.

in opinion jri better rserve, because instead of creating separate process uses native calls integrate java , r.

with jri don't have worry ports, connections, watchdogs, etc... calls r done using operating system library (libjri).

the methods pretty similar rserve, , can still use rexp objects.

here example:

public void testmeanfunction() {      // making sure have right version of     if (!rengine.versioncheck()) {         system.err.println("** version mismatch - java files don't match library version.");         fail(string.format("invalid versions. rengine must have same version of native library. rengine version: %d. rni library version: %d", rengine.getversion(), rengine.rnigetversion()));     }      // enables debug traces     rengine.debug = 1;      system.out.println("creating rengine (with arguments)");     // 1) pass arguments command line     // 2) won't use main loop @ first, we'll start later     // (that's "false" second argument)     // 3) no callback class used     engine = rengine.engineforclass("org.rosuda.rengine.jri.jriengine", new string[] { "--no-save" }, null, false);     system.out.println("rengine created...");      engine.parseandeval("rvector=c(1,2,3,4,5)");     rexp result = engine.parseandeval("meanval=mean(rvector)");     // generic vectors rvector accomodate names     assertthat(result.asdouble()).isequalto(3.0); } 

i have demo project exposes rest api , calls r functions using package.

take at: https://github.com/jfcorugedo/rjavaserver


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -