@Test
  public void testStack2() {
    double[][] data =
        new double[][] {
          {197.136, 124.32, 63.492, 59.052},
          {124.32, 78.4, 40.04, 37.24},
          {63.492, 40.04, 20.449, 19.019},
          {59.052, 37.24, 19.019, 17.689}
        };
    RCaller caller = new RCaller();
    Globals.detect_current_rscript();
    caller.setRscriptExecutable(Globals.Rscript_current);
    RCode code = new RCode();

    code.addDoubleMatrix("mydata", data);
    code.addRCode("result <- chisq.test(mydata)");
    code.addRCode("mylist <- list(pval = result$p.value, df=result$parameter)");

    caller.setRCode(code);
    caller.runAndReturnResult("mylist");

    double pvalue = caller.getParser().getAsDoubleArray("pval")[0];
    double df = caller.getParser().getAsDoubleArray("df")[0];
    System.out.println("Pvalue is : " + pvalue);
    System.out.println("Df is : " + df);
    caller.deleteTempFiles();
  }
  /**
   * returns a single Double result. Assumes that the R code uses the variable "results" for storing
   * the results of the process.
   *
   * @param template
   * @return
   */
  protected Double getSingleResult(String template) {
    code.clear();
    code.addRCode(template);

    String call = "results";

    caller.setRCode(code);
    caller.runAndReturnResultOnline(call);
    String[] res = caller.getParser().getAsStringArray(call);

    // the codestore is always updated at the end of the operation
    addToCodestore(code, call);

    return convertStringToNumber(res[0]);
  }
  protected void installPackageIfNotInstalled(String packageName) {
    code.clear();
    code.addRCode(
        "if(!('"
            + packageName
            + "' %in% installed.packages()[,\"Package\"])){install.packages('"
            + packageName
            + "')}");
    caller.setRCode(code);

    String call = "library('" + packageName + "')";

    caller.runAndReturnResultOnline("library('" + packageName + "')");
    // the codestore is always updated at the end of the operation
    addToCodestore(code, call);
  }
 protected void clearAndSetCode(String somecode) {
   code.clear();
   code.addRCode(somecode);
   caller.setRCode(code);
 }