title: Why do R objects not print in a function or a "for" loop?
body: <p>I have an R matrix named ddd. When I enter this, everything works fine:</p>
  
  <pre><code>i &lt;- 1
  shapiro.test(ddd[,y])
  ad.test(ddd[,y]) 
  stem(ddd[,y]) 
  print(y) 
  </code></pre>
  
  <p>The calls to Shapiro Wilk, Anderson Darling, and stem all work, and extract the same column.</p>
  
  <p>If I put this code in a "for" loop, the calls to Shapiro Wilk, and Anderson Darling stop working, while the the stem &amp; leaf call and the print call continue to work.</p>
  
  <pre><code>for (y in 7:10) {
      shapiro.test(ddd[,y])
      ad.test(ddd[,y]) 
      stem(ddd[,y]) 
      print(y)
  }
  
  The decimal point is 1 digit(s) to the right of the |
  
    0 | 0
    0 | 899999
    1 | 0
  
  [1] 7
  </code></pre>
  
  <p>The same thing happens if I try and write a function. SW &amp; AD do not work. The other calls do. </p>
  
  <pre><code>&gt; D &lt;- function (y) {
  + shapiro.test(ddd[,y])
  + ad.test(ddd[,y]) 
  + stem(ddd[,y]) 
  + print(y)  }
  
  &gt; D(9)
  
    The decimal point is at the |
  
     9 | 000
     9 | 
    10 | 00000
  
  [1] 9
  </code></pre>
  
  <p>Why don't all the calls behave the same way?</p>