1
    import java.io.IOException;
    import java.lang.Runtime;
    import rcaller.RCaller;
    import rcaller.RCode;

    public class SurvivalAnalysis {
    public static void main(String[] args) throws IOException{

    RCode code = new RCode();
    RCaller caller = new RCaller();
    caller.setRscriptExecutable("path\Rscript.exe");

    String path="cmd /c start path\\SAbatch.bat";
    Runtime rn=Runtime.getRuntime();
    Process pr=rn.exec(path);
    Runtime.getRuntime().exec("cmd /c path/SurvivalAnalysis.r");

    code.addRCode("require(survival)");
    code.addRCode("require(flexsurv)");
    code.addRCode("DataTest <- read.csv('C:path/data.csv',header=TRUE, sep=',')");
    code.addRCode("TestModelF_W <- flexsurvreg(Surv(time,death,type='right') ~ timeZone1, data = DataTest, dist = 'weibull')");
    caller.runAndReturnResult("summary(TestModelF_W)");
    caller.setRCode(code);

}

}

I am trying to perform a survival analysis on a .CSV data file by using the R package flexsurvreg. My parent code is in Java so I am calling R from java. I am using the RCaller package to do this, based on the this SO post.

When running the code, I get the following error message:

    [Fatal Error] Routput3149779333722388628:1:1: Premature end of file.
    packageExist<-require(Runiversal)
    if(!packageExist){
    install.packages("Runiversal", repos=" http://cran.r-project.org")
    }

    packageExist<-require(Runiversal)
    if(!packageExist){
    install.packages("Runiversal", repos=" http://cran.r-project.org")
    }

    cat(makexml(obj=summary(TestModelF_W), name="summary(TestModelF_W)"), 
    file="C:/Users/User/AppData/Local/Temp/Routput3149779333722388628")

    Exception in thread "main" rcaller.exception.RCallerExecutionException: 
    Can not handle R results due to : 
    rcaller.exception.RCallerParseException: Can not parse the R output: 
    org.xml.sax.SAXParseException; systemId: file:/C:/Users/Chaitu/AppData/Local/Temp/Routput3149779333722388628; lineNumber: 1; columnNumber: 1; Premature end of file.
at rcaller.RCaller.runAndReturnResult(RCaller.java:402)
at SurvivalAnalysis.main(SurvivalAnalysis.java:22)

In order to debug, I tried calling creating an R script and calling that directly from Java, but that seems to have the same problem. RCaller documentation has no leads for this.

caller.R_source(path/SurvivalAnalysis.r");
caller.runOnly();

0 Answers0