title: Running R from terminal via Java
body: <p>I'm trying to run R using Java. I have R installed on my Mac and I've used it plenty of times from the terminal.</p>
  
  <p>In the terminal, to start R, one simply types "R"</p>
  
  <p>Ex:</p>
  
  <pre><code> Macintosh-11:Desktop myname$ R
  
  R version 2.12.2 (2011-02-25)
  Copyright (C) 2011 The R Foundation for Statistical Computing
  ISBN 3-900051-07-0
  Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
  
  R is free software and comes with ABSOLUTELY NO WARRANTY.
  You are welcome to redistribute it under certain conditions.
  Type 'license()' or 'licence()' for distribution details.
  
    Natural language support but running in an English locale
  
  R is a collaborative project with many contributors.
  Type 'contributors()' for more information and
  'citation()' on how to cite R or R packages in publications.
  
  Type 'demo()' for some demos, 'help()' for on-line help, or
  'help.start()' for an HTML browser interface to help.
  Type 'q()' to quit R.
  
  &gt; 
  </code></pre>
  
  <p>So, what I would like to do is run R through Java, via the terminal. So, I wrote myself a Java class:</p>
  
  <pre><code>public class javar {
  
          public static void main(String[] args) throws Exception {
                  Runtime.getRuntime().exec("R");
          }
  }
  </code></pre>
  
  <p>However, when I compile and then execute, using</p>
  
  <pre><code>java javar
  </code></pre>
  
  <p>I don't see R start. I simply see the program finish executing, and then the terminal is ready for another command.</p>
  
  <p>How can I achieve what I'm trying to do?</p>