title: R - capturing elements of R output into text files
body: <p>I am trying to run an analysis by invoking R through the command line as follows: </p>
  
  <pre><code>R --no-save &lt; SampleProgram.R &gt; SampleProgram.opt
  </code></pre>
  
  <p>For example, consider the simple R program below: </p>
  
  <pre><code>mydata = read.csv("test.txt", header=T)
  attach(mydata)
  summary(Variable1)
  q()
  </code></pre>
  
  <p>The output is displayed in SampleProgram.opt (only partially shown): </p>
  
  <pre><code>&gt; mydata = read.csv("test.txt", header=T)
  &gt; attach(mydata)
  &gt; summary(Variable1)
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
     1.00    1.00    2.00    2.47    3.00    4.00
  &gt; q()
  </code></pre>
  
  <p>This simple R program is going to be executed by a script that needs to use the summary statistics displayed for Variable1. </p>
  
  <p>The question is this: Is there any way in R to capture the output of summary(Variable1) and write the results into an output file? In other words, I need R to run the summary statistics for Variable1, capture the "Min", "Median" and "Max" values and write those alone to an output text file. In this example, the output file should contain only one line with the values "1.00, 2.00, 4.00" (i.e. the "Min", "Median" and "Max" values). </p>
  
  <p>The example above talks about the summary function. But, I need to do that with other commands as well (such as glm)</p>
  
  <p>I am fairly new to R and was wondering if there was a way in R that I could do this? </p>
  
  <p>Thanks for the help.  </p>