[Rd] JRI and error message from R_isMethodsDispatchOn
Simon Urbanek
simon.urbanek at r-project.org
Sat Nov 20 08:39:43 CET 2010
Keith,
On Nov 19, 2010, at 7:40 PM, Keith wrote:
> Dear R users,
>
> I have a small project written in Java and need some statical tools. Therefore, I used JRI (in rJava package) as an interface between R and Java to write some wrappers for my work. However, I received error message from R while I have more than one java method which wraps R:
>
> Error in .Call("R_isMethodsDispatchOn", onOff, PACKAGE = "base") :
> Incorrect number of arguments (2), expecting 1 for R_isMethodsDispatchOn
>
> The Java pseudo code would be like:
>
> public class Test{
> public static void main(String[] args){
> ...
> objA.do;
> objB.do;
> ...
> }
> }
>
> Each do method actually calls R to do the job. I already know R is single-treaded so I implemented end method in Rengine class to shutdown R in each method.
You cannot shutdown R short of closing the process and thus JVM, so that is not an option. In fact NOT using end will likely solve your problem - simply used one, shared instance of the REngine.
> I thought this won't cause multi-thread problems in this case because I terminate/destroy each R thread before I call another one. But, it seems that it's still considered as 2 threads. Did I miss something? or probably, I have to set-up JRI server for my project? or other recommendations for my purpose?
>
Simply use one instance of REngine continuously - that's the only approach possible with JRI (note that the R access is synchronized so you can use the instance from different threads). If you need multiple instances, you can use Rserve - it uses the same REngine API but allows you to have arbitrarily many parallel instances.
BTW: please use stats-rosuda-devel mailing list of questions related to rJava, JRI or Rserve. It's also worth scanning the archives as those issues have been raised before.
Cheers,
Simon
> R version: 2.11.1
> rJava version: 0.8-4
> OS: Arch Linux
>
> Best,
> Keith
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
More information about the R-devel
mailing list