title: write a gzip file from data frame
body: <p>I'm trying to write a data frame to a gzip file but having problems.</p>
  
  <p>Here's my code example:</p>
  
  <pre><code>df1 &lt;- data.frame(id = seq(1,10,1), var1 = runif(10), var2 = runif(10))
  
  gz1 &lt;- gzfile("df1.gz","w" )
  writeLines(df1)
  </code></pre>
  
  <blockquote>
    <p>Error in <code>writeLines(df1)</code> : invalid 'text' argument</p>
  </blockquote>
  
  <p>Any suggestions?</p>
  
  <p>EDIT:
  an example line of the character vector I'm trying to write is:</p>
  
  <pre><code>0 | var1:1.5 var2:.55 var7:1250
  </code></pre>
  
  <p>The class label / y-variable is separated from the x-vars by a " | " and variable names are separated from values by " : " and spaces between variables.</p>
  
  <p>EDIT2:
  I apologize for the wording / format of the question but here are the results:
  Old method:</p>
  
  <pre><code>system.time(write(out1, file="out1.txt"))
  #    user  system elapsed 
  #   9.772  17.205  86.860 
  </code></pre>
  
  <p>New Method:</p>
  
  <pre><code>writeGzFile &lt;- function(){
    gz1 = gzfile("df1.gz","w");
    write(out1, gz1);
    close(gz1) 
  }
  
  system.time( writeGzFile())
  #    user  system elapsed 
  #   2.312   0.000   2.478 
  </code></pre>
  
  <p>Thank you all very much for helping me figure this out.</p>