title: How to minimize size of object of class "lm" without compromising it being passed to predict()
body: <p>I want to run <code>lm()</code> on a large dataset with 50M+ observations with 2 predictors. The analysis is run on a remote server with only 10GB for storing the data. I have tested ´lm()´ on 10K observations sampled from the data and the resulting object had size 2GB+. </p>
  
  <p><strong>I need the object of class "lm" returned from <code>lm()</code> ONLY to produce the summary statistics of the model (<code>summary(lm_object)</code>) and to make predictions (<code>predict(lm_object)</code>).</strong> </p>
  
  <p>I have done some experiment with the options <code>model, x, y, qr</code> of <code>lm</code>. If I set them all to <code>FALSE</code> I reduce the size by 38% </p>
  
  <pre><code>library(MASS)
  fit1=lm(medv~lstat,data=Boston)
  size1 &lt;- object.size(fit1)
  print(size1, units = "Kb")
  # 127.4 Kb bytes
  fit2=lm(medv~lstat,data=Boston,model=F,x=F,y=F,qr=F)
  size2 &lt;- object.size(fit2)
  print(size2, units = "Kb")
  # 78.5 Kb Kb bytes
  - ((as.integer(size1) - as.integer(size2)) / as.integer(size1)) * 100
  # -38.37994
  </code></pre>
  
  <p>but</p>
  
  <pre><code>summary(fit2)
  # Error in qr.lm(object) : lm object does not have a proper 'qr' component.
  #  Rank zero or should not have used lm(.., qr=FALSE).
  predict(fit2,data=Boston)
  # Error in qr.lm(object) : lm object does not have a proper 'qr' component.
  #  Rank zero or should not have used lm(.., qr=FALSE).
  </code></pre>
  
  <p>Apparently I need to keep <code>qr=TRUE</code> which reduce the object size by only 9% if compared with the default object</p>
  
  <pre><code>fit3=lm(medv~lstat,data=Boston,model=F,x=F,y=F,qr=T)
  size3 &lt;- object.size(fit3)
  print(size3, units = "Kb")
  # 115.8 Kb
  - ((as.integer(size1) - as.integer(size3)) / as.integer(size1)) * 100
  # -9.142752
  </code></pre>
  
  <p>How do I bring the size of the "lm" object to a minimum without dumping a lot of unneeded information in memory and storage?</p>