Home:ALL Converter>How I can load add-on R libraries into JRI and execute from Java?

How I can load add-on R libraries into JRI and execute from Java?

Ask Time:2013-06-12T21:48:24         Author:novicegeek

Json Formatter

I am working with a Java and I need to use an add-on R library and use the functions within that library. I tried the answers provided in the following questions

How I can load a R script into JRI and execute from Java?

Problem loading R own created libraries in Java/JRI code

but I still get a NullPointerException. Can anyone point out the error. Thankyou

Here is the code which I am using:

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.RVector;
import org.rosuda.JRI.Rengine;

public class RConnect { 

public void processFiles(String[] spectrumData)
{
    // new R-engine
    Rengine re=new Rengine (new String [] {"--vanilla"}, false, null);
    if (!re.waitForR())
    {
        System.out.println ("Unable to load R");
        return;
    }
    else
        System.out.println ("Connected to R");

    REXP rexpSetFolder = re.eval("setwd('/home/user/R/x86_64-pc-linux-gnu-library/3.0')");
    REXP rexpFolder = re.eval("getwd()");
    System.out.println(rexpFolder.asString());

    REXP rexpLoad = re.eval("library(PROcess)");
    RVector f1 = (re.eval("read.files(spectrumData)").asVector());
    System.out.println(f1);

    re.end();
}
}

Author:novicegeek,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/17067236/how-i-can-load-add-on-r-libraries-into-jri-and-execute-from-java
yy