简体   繁体   中英

org.rosuda.REngine.Rserve.RserveException: eval failed while running R script from java

I am getting the RserveExcpetion called org.rosuda.REngine.Rserve.RserveException: eval failed while running the below code.

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

public class Temp {

public static void main(String a[]) {
    RConnection connection = null;

    try {
        /* Create a connection to Rserve instance running on default port
         * 6311
         */
        connection = new RConnection();

        /* Note four slashes (\\\\) in the path */
        connection.eval("source('F:\\testFiles\\svm.R')"); //Here getting the exception
        int num1=10;
        int num2=20;
        int sum=connection.eval("myAdd("+num1+","+num2+")").asInteger();
        System.out.println("The sum is=" + sum);

    } catch (RserveException e) {

        e.printStackTrace();

    } catch (REXPMismatchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
}
}

How to solve this problem

that is because the R function myAdd() was not initialized correctly by reading in the source file. Try the answer from here: Calling R from Java using RServe weird error using a try-catch statement to see the actual R error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM