tags:

views:

238

answers:

1

I have a system set up that's been happily running R from a java servlet, spawning processed & hooking into the process's stdin, stdout, and stderr streams, as in the second andwer to this question.

After a system upgrade (that included glibc), the input is no longer reaching the R process.*

Until now, 'R --vanilla --slave -f [file] ...' was working fine for me. I also have no swing dependencies right now, so I'm somewhat reluctant to add them. (I may actually not be able to add swing dependencies; am I right that using REngine automatically brings swing in? The examples import all of swing.)

Are there advantages to switching to JRI? What changes would I need to make to my R script? (It currently reads from stdin and writes to stdout). I'm not finding the provided examples terribly helpful for how to use JRI in this situation.

Thanks for your help & comments.

*I can't even tell if the problem is data being written too soon or too late, but that's a separate issue/question; if I move to JRI I'm hoping it all becomes moot.

+2  A: 

My two cents:

I find working with JRI to be straight-forward. There are several examples provided with JRI that give a good demonstration of how to use it.

In general, you shouldn't have to make any major changes to your script because you can simply pass in an entire script as an expression with the eval() function and then handle the return value. The main advantage as I see it is that you're then handling the R process from within your Java code, so you can with exceptions properly without having to make any system calls. JRI also provides some R data type equivalents in Java such as RVector.

Shane
Thanks for the thoughts! Sadly, it looks easy if I'm doing something standalone, and has been a total nightmare trying to get it working in a maven build (for tomcat hosting etc). Even after following instructions in things like http://buildanddeploy.com/node/14, it resolutely won't find the JRI native library.
LH
Did you try just taking the Jar files that come with rJava?
Shane
Yup. I started with them, put them into the build path, and got the classic "Cannot find JRI native library!Please make sure that the JRI native library is in a directory listed in java.library.path."Which is when I started down the path of trying to get it to find the libjri.jnilib (I'm working on a mac at the moment) by the aforementioned shenanigans. And utterly failing. sigh.
LH