title: Memory Issues in R CRAN Package
body: <p>I have successfully  uploaded R package in CRAN. Now I want to publish its article. Reviewer 2 returned the paper due to <strong>memory usage issues</strong>. Now I am confused about this objection, how to solve this.
  Generally, my package is about density plots and I create S3 class for each style of plot. Almost each function used 2 <code>for</code> loops otherwise code is not too long. But according to <a href="http://adv-r.had.co.nz/memory.html" rel="nofollow noreferrer">Advanced R</a> <code>for</code> loops are slow. So what is best alternative?
  <em><strong>Chunk of Code</strong></em></p>
  <pre><code>xxx&lt;-function(y,k,h){
  n&lt;-length(y)
   x &lt;- seq(min(y) + 0.05, max(y), length =k)
   K &lt;- matrix(rep(0, k * n), ncol = k)
   fhat &lt;- rep(0, k)
  ###########Loops###########
  for(j in 1:k) {
  for(i in 1:n) {
  ####main code###
  }
  fhat[j] &lt;- 1/n * (sum(K[, j]))
  }
  results &lt;- list(x=x, y=fhat)
  
  class ( results ) &lt;-c('list', 'XXX')
  results
  }
  </code></pre>
  <p><code>k</code> is grid point and defined by user. What is the problem and how to solve this? Additionally, they wrote code writing style is not too good; How I can improve this?</p>