Samstag, 29. Dezember 2012

Lots of statisticians, psychologists, physicists use R as their universal statistical tool. Others just employ the power of R within another programming language to leverage well-tested statistical tools with specialist tools.
In this article I want to show how you can combine JAVA with R.
Start with an installation of either R or JAVA first. After you have finished you need Rserve. You might want to follow the instructions from the Rserve doc. The simplest way is to launch R cli and use the command

install.packages("Rserve")


There are multiple ways of starting the Rserve server. Linux users are usually well aware of their paths and dependencies. But on Windows systems you might have several installations, like 32 and 64 bit and need to start the Rserve that fits your installation. Using the command line tool you should be able to start Rserve as follows

>C:\tools\R\R-2.14.2\bin\i386\R.exe CMD C:\Users\rse\Documents\R\win-library\2.14\Rserve\libs\i386\Rserve.exe --no-save --vanilla
Ok, ready to answer queries.

When you know, you can start Rserve and thus use R from JAVA.

Starting this Rserve server any time is again and again is annoying. So when you used JAVA for some time you certainly stumbled upen the spring framework. Wouldn't it be nice, instead of starting Rserve over and over again, but use some Spring magic and just have a code like:

@Autowired IRConnection managedConnection;

The project j.o.r.i.s provides that type of spring magic. Apart from auto-starting Rserve there is a handy wrapper class for Rconnections, database tools and much more I will write about in a later post.