title: Scan for string across multiple files with R
body: <p>I would like to scan multiple files for strings in R and know which file names have that string.</p>
  
  <p>Is there a way to do this with something like grep, cat, readLines in a function maybe?</p>
  
  <p>If I scan the files using:</p>
  
  <pre><code>fileNames &lt;- Sys.glob("*.csv")
  </code></pre>
  
  <p>then maybe something like: </p>
  
  <pre><code>for (f in fileNames) {
      stuff &lt;- read.csv(fileName, sep = ",")
      grep("string")
  
  }
  
  names(res) &lt;- substr(filenames, 1, 30)
  </code></pre>
  
  <p>Or maybe even better, a loop like this:</p>
  
  <pre><code>for( f in  filenames ){
     cat("string", file=f)
  }
  
  for( f in filenames) {
      cat(readLines(f), sep="\n")
  }
  </code></pre>
  
  <p>This code doesn't work, I'm just trying to think this through. Im certain there is a better way to do this. It sounds simple but I cant get it right.</p>
  
  <p>I want to scan files for strings and then have the output of the filenames where the string was found. I have not found an example to do this in R.</p>
  
  <p>Suggestions?</p>