title: R loop opening files
body: <p>I am trying to run a simple 5 lines command but over 9000 different files. I wrote the following for loop</p>
  
  <pre><code>setwd("/Users/morandin/Desktop/Test")
  output_file&lt;- ("output_file.txt")
  files &lt;- list.files("/Users/morandin/Desktop/Test")
  for(i in files) {
    chem.w.in &lt;- scan(i, sep=",")
    pruned.tree&lt;-drop.tip(mytree,which(chem.w.in %in% NA))  
    plot(pruned.tree)
    pruned.tree.ja.chem.w.in &lt;- phylo4d(pruned.tree, c(na.omit(chem.w.in)))
    plot(pruned.tree.ja.chem.w.in) 
    out &lt;- abouheif.moran(pruned.tree.ja.chem.w.in)
    print(out)
  }
  </code></pre>
  
  <p>Hey I am editing my question: the above code does the for loop perfectly now (thanks for all your help). I am still having an issue with the output.</p>
  
  <p>I can redirect the entire output using R through bash commands but I would need the name of the processed file. My output looks like this:</p>
  
  <pre><code>class: krandtest 
  Monte-Carlo tests
  Call: as.krandtest(sim = matrix(res$result, ncol = nvar, byrow = TRUE), 
      obs = res$obs, alter = alter, names = test.names)
  
  Number of tests:   1 
  
  Adjustment method for multiple comparisons:   none 
  Permutation number:   999 
    Test       Obs   Std.Obs   Alter Pvalue
  1   dt 0.1458514 0.7976225 greater    0.2
  
  other elements: adj.method call
  </code></pre>
  
  <p>Is there a way to print Pvalue results and name of the file (element i)??</p>
  
  <p>Thanks</p>