Subhash Verma
Subhash Verma

Reputation: 11

Rserve Error in file(filename, "r", encoding = encoding) : cannot open the connection

public class InitialCondition {
public static void main(String[] args) {
    ObjectMapper mapper = new ObjectMapper();
  RConnection c =null;
   try {
             c =new RConnection();
   
       REXP rScriptExec= c.eval(String.format("try(source('C:/Users/Sverma/Desktop/data/R/Polecondition_&InitialCon/InitialConditions_V3.R'),silent=TRUE)"));
              if (rScriptExec.inherits("try-error")){
                System.out.println(rScriptExec.asString());
            }else{
                 REXP resultInitalRejectrate = c.eval("Rejectrate");
                REXP InitalDBSrate_initial = c.eval("DBSrate");

                 REXP dataRate = c.eval("poleCondition");
                System.out.println("resultInitalRejectrate->"+resultInitalRejectrate.asDouble());
                 System.out.println("InitalDBSrate_initial->"+InitalDBSrate_initial.asDouble());
                 JsonNode t=mapper.readTree(dataRate.asString());
                 System.out.println("InitalDBSrate_initial->"+t.toPrettyString());
                
             }
   } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(c!=null) {
                c.close();
                System.out.println("Connection closed..");
            }
        }
}

}

I have the RScript file (let's call it InitialConditions_V3.r) which has the reference to another file, using the following code. Getting below exception in java Error in file(filename, "r", encoding = encoding) : cannot open the connection

Upvotes: 0

Views: 907

Answers (1)

Subhash Verma
Subhash Verma

Reputation: 11

I solved this issue, there was script file name issue

Upvotes: 0

Related Questions