title: How I can load add-on R libraries into JRI and execute from Java?
body: <p>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</p>
  
  <p><a href="https://stackoverflow.com/questions/8037411/how-i-can-load-a-r-script-into-jri-and-execute-from-java">How I can load a R script into JRI and execute from Java?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2477398/problem-loading-r-own-created-libraries-in-java-jri-code">Problem loading R own created libraries in Java/JRI code</a></p>
  
  <p>but I still get a NullPointerException. Can anyone point out the error. Thankyou </p>
  
  <p>Here is the code which I am using:</p>
  
  <pre><code>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();
  }
  }
  </code></pre>