3

I am getting an exception while trying to run a R program via Java. The connection is being established but then the error is being thrown while the evaluation of the R code starts.

Rconnection connection = new RConnection();

System.out.println(String.valueOf(connection.isConnected())); //Output: True
connection.eval("source('C:\\Users\\Vini\\Documents\\test.R')"); //Exception in this line

I have already started the Rserve in R.

java.net.SocketException: Connection reset
  at java.net.SocketInputStream.read(SocketInputStream.java:209)
  at java.net.SocketInputStream.read(SocketInputStream.java:141)
  at java.net.SocketInputStream.read(SocketInputStream.java:127)
  at org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:213)
  at org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:180)
  at org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:250)
  at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:231)
  at integration.Integration.main(Integration.java:36)
org.rosuda.REngine.Rserve.RserveException: eval failed
  at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:234)
  at integration.Integration.main(Integration.java:36)
vsminkov
  • 10,912
  • 2
  • 38
  • 50
Vini
  • 1,978
  • 8
  • 40
  • 82

1 Answers1

0

The problem is that isConnected does not guarantee that after connection was established it will report correct state:

Note that currently this state is not checked on-the-spot, that is if connection went down by an outside event this is not reflected by the flag

You need to check Rserve log to check that request was processed successfully

vsminkov
  • 10,912
  • 2
  • 38
  • 50
  • i cannot execute the code above because it is taking too long to establish a connection – Vini Sep 05 '16 at 09:32