0

Hi I am setting up rserve based on the instructions on this website. http://www.codophile.com/how-to-integrate-r-with-java-using-rserve/

However in eclipse I am getting an error when using 'eval'

             double d[] = c.eval("rnorm(10)").asDoubles();

error - 'The method eval(String) is undefined for the type RConnection'

The JARS have been correctly loaded into the build path and rserve is running, however I cannot figure out why only the eval function is causing an issue.

In addition to this the import of ...

   import org.rosuda.REngine.Rserve.RConnection;

causes an error - 'The import org.rosuda.REngine.Rserve.RConnection conflicts with a type defined in the same file'

does anyone have any idea why this is the case? Thanks

all imports :

import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;




 public class RConnection {
public int[] mean(String a[]) {

    setupR();        

    return null;
}

public void setupR(){

    try {

        /* Create a connection to Rserve instance running
         * on default port 6311
         */

        RConnection c = new RConnection();// make a new local connection on default port (6311)

        double d[] = c.eval("rnorm(10)").asDoubles();
        org.rosuda.REngine.REXP x0 = c.eval("R.version.string");
        System.out.println(x0.asString());

    } catch (RserveException e) {
        e.printStackTrace();
    } catch (REXPMismatchException e) {
        e.printStackTrace();
    }
}
}
5
  • Can you edit your post to include all the import statements from that file? You seem to import something that may also have an RConnection class. Commented Dec 20, 2015 at 16:42
  • Hi I put all the updated imports in my question. Commented Dec 20, 2015 at 16:45
  • Those imports look OK. Do you have a RConnection type defined in that file? Commented Dec 20, 2015 at 16:49
  • I will paste the whole class in (its quite small) Commented Dec 20, 2015 at 16:50
  • It is now updated, thanks. Commented Dec 20, 2015 at 16:52

1 Answer 1

2

By using import org.rosuda.REngine.Rserve.RConnection; you are tying to make RConnection known in the local namespace. However, you already defined a class called RConnection locally.

Please rename your class RConnection, and you should be able to import org.rosuda.REngine.Rserve.RConnection.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, I feel like a total idiot now after realising what my mistake was. a huge thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.