[R] Fwd: REngine hangs when called within java code

aruni karunarathne arunikarunarathne at gmail.com
Sun Apr 19 03:51:24 CEST 2015


Dear All,

I fixed my issue.

 String newargs1[] = {"--no-save"};

        Rengine r1 = Rengine.getMainEngine();
       if (r1 == null) {
           r1 = new Rengine(newargs1, false, null);
       }

i added/modified the above part when setting up the rengine.
Somehow, now it works.
may be that in the previous coding, one instance of rengine do not
really end.hence it hangs when it comes to another instance.

Many thanks.


---------- Forwarded message ----------
From: aruni karunarathne <arunikarunarathne at gmail.com>
Date: Wed, Apr 15, 2015 at 11:17 PM
Subject: REngine hangs when called within java code
To: r-help at r-project.org


Dear All,

I'm creating a project which uses both java and R.

I created the java class named MyClass and within that wrote two
separate methods (graphing1() and fitness()) to call the r scripts.

public void graphing1() throws IOException {

    String newargs1[] = {"--no-save"};

    Rengine r1 = new Rengine(newargs1, false, null);

    r1.eval("source('test2.R')");

    r1.end();

}



public void fitness() throws IOException {

    String newargs1[] = {"--no-save"};

    Rengine r3 = new Rengine(newargs1, false, null);

    r3.eval("source('A.R')");

    r3.eval("source('B.R')");

    r3.end();

}

Both of the above methods are in java class MyClass.

>From another class in the same project for which I created a gui, I
accessed the fitness() function and it worked fine. But when I try to
call the graphing1() function it did not work. (both were called
through the gui) The programme hangs at ;

Rengine r1 = new Rengine(newargs1, false, null);

without any notification. In both instances I called the function as follows:

1st instance:

MyClass test=new MyClass();

    test.fitness() ;

2nd instance:

MyClass test1 = new MyClass();

        test1.graphing1();



All the 3 scripts are coded to create png files. test2.R and A.R
scripts use the ROCR library and B.R do not use any. All the 3 files
end with dev.off() statement.

I have installed R 3.1.3. I’m using netbeans as the editor and working
in windows environment.

The 3 scripts work fine when executed in R environment. The issue
arises when it’s called from the java code.

I'm a student who is new to R and was struggling to solve this issue
for several weeks. Your help is greatly appreciated.

Thanks in advance.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: REngine hangs when called within java code -- problem.pdf
Type: application/pdf
Size: 48699 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150419/c56015b6/attachment.pdf>


More information about the R-help mailing list