title: for.loop with WAV files
body: <p>I'm trying to create a loop for reading in stereo wave files in R, but I'm unsure if I should use for.loop or while.loop.  I'm calculating the RMS for both channels.</p>
  
  <p>Here's the action for one sound file:</p>
  
  <pre><code>foo=readWave("mysound.wav")
  L=foo@left
  R=foo@right
  rms(L)
  rms(R)
  </code></pre>
  
  <p>Now, I have directories full of 2 minute sound files.  I want to take each of those files, isolate the channels, and calculate the RMS.  I THINK this is how it's done:</p>
  
  <pre><code>mydir=list.files("directory", recursive=TRUE) 
  for (i in 1:length(mydir)) {
      foo=readWave(mydir[i])
      L=foo@left
      R=foo@right
      rms(L)
      rms(R)
      write(combine, file="test.txt", append=true, sep="\t")  
  }
  </code></pre>
  
  <p>This loop returns the error message that my first sound files doesn't exist.  As per the suggestion below, I've also tried to read in the files by:</p>
  
  <pre><code>wav_files &lt;- lapply(mydir, readWave)
  Error in FUN(c("DASBR2_20131112$224708.wav", "DASBR2_20131112$224910.wav",  : 
     File 'DASBR2_20131112$224708.wav' does not exist.
  </code></pre>
  
  <p>This also returns that my file does not exist.  Perhaps there is a better way to read in the wave files?  Can lapply or for.loop handle waves?  </p>
  
  <p>When I type mydir into the console, R produces the following output:</p>
  
  <pre><code>&gt; mydir
     [1] "DASBR2_20131112$224708.wav" "DASBR2_20131112$224910.wav"
     [3] "DASBR2_20131112$225110.wav" "DASBR2_20131112$225310.wav"
     [5] "DASBR2_20131112$225446.wav" "DASBR2_20131112$225648.wav"
     ...
  </code></pre>
  
  <p>This is what I expect, as these are the names of my sound files.  Thoughts?</p>