title: Extract r symbolic regression best model in java
body: <p>I am calling R symbolic regression function from java by passing r script using Rengine. 
   As I try to extract the best model in Java I get null. I could tell by extracting another value(s$bestFitness) from the symbolic regression result that it is not null so it looks I am extracting the best model the wrong way.  As I see in this tutorial: <a href="http://www.studytrails.com/RJava-Eclipse-Plugin/Execute-R-From-Java.jsp" rel="nofollow">http://www.studytrails.com/RJava-Eclipse-Plugin/Execute-R-From-Java.jsp</a> how they extract the intercept from linear regression result using asVector().at[i].asDoubleArray()[j]. I thought the solution to my problem should look similar. I could not figure out why they did it this way so I could not map the solution to my problem. Any tips on extracting the best model would be very much appreciated.
  Here is my code: </p>
  
  <pre><code>import org.rosuda.JRI.REXP;
  import org.rosuda.JRI.RVector;
  import org.rosuda.JRI.Rengine;
  import org.rosuda.REngine.REXPMismatchException;
  import org.rosuda.REngine.REngineException;
  import org.rosuda.REngine.JRI.JRIEngine;
  public class REn {
  
  public static void main(String[] args) throws REngineException, REXPMismatchException {
      org.rosuda.REngine.REngine r;
      REXP result;
      String df="df";
      String y="reponceTime";
      String x="nodes"; 
      Rengine rengine = new Rengine (new String [] {"--vanilla"}, false, null);
      // Check if the session is working.
      if (!rengine.waitForR()) {
          return;
      }
  
      r=new JRIEngine(rengine);
      // load library to perform symbolic regression
      rengine.eval("library(rgp)");   
  
      rengine.eval(x+" &lt;- c(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0)");
      rengine.eval(y+" &lt;- c(33205.8, 29279.24, 27775.28, 24074.12, 22360.44, 19737.6, 19374.88, 18794.12, 18687.88)");
      rengine.eval(df+" &lt;- data.frame("+x+", "+y+")");
  
      String symbolic="s &lt;- symbolicRegression("
              + y+" ~ "+ x+ ", data="+ df
              + ",functionSet=arithmeticFunctionSet, stopCondition=makeStepsStopCondition(30))";
  //      + ",functionSet=fs, stopCondition=makeStepsStopCondition(2000))";
  
  System.out.println("Executing: "+ symbolic);
      rengine.eval(symbolic);
  
      result=rengine.eval("s$bestFitness");
      System.out.println("bestFitness is "+result);
  
      rengine.eval("bm &lt;- s$population[[which.min(s$fitnessValues)]]");
      result=rengine.eval("bm");
      System.out.println("bm is "+result);
      r.close();      
  
  } }
  </code></pre>
  
  <p>and the result I get is:</p>
  
  <pre><code>Executing: s &lt;- symbolicRegression(reponceTime~ nodes, data=df,functionSet=arithmeticFunctionSet, stopCondition=makeStepsStopCondition(30))
  bestFitness is [REAL* (19040.339878315513)]
  bm is [NULL]
  </code></pre>