title: SQL query with comments import into R from file
body: <p>A few posters have asked similar questions on here and these have taken me 80% of the way toward reading text files with sql queries in them into R to use as input to RODBC:</p>
  
  <p><a href="https://stackoverflow.com/questions/2003663/r-language-import-multiline-sql-query-to-single-string">Import multiline SQL query to single string</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4747768/rodbc-temporary-table-issue-when-connecting-to-ms-sql-server/4748281#4748281">RODBC Temporary Table Issue when connecting to MS SQL Server</a></p>
  
  <p>However, my sql files have quite a few comments in them (as --comment on this and that). My question is, how would one go about either stripping comment lines from query on import, or making sure that the resulting string keeps line breaks, thus not appending actual queries to comments?</p>
  
  <p>For example, query6.sql:</p>
  
  <pre><code>--query 6
  select a6.column1, 
      a6.column2,
      count(a6.column3) as counts
  --count the number of occurences in table 1 
  from data.table a6
  group by a6.column1
  </code></pre>
  
  <p>becomes:</p>
  
  <pre><code>sqlStr &lt;- gsub("\t","", paste(readLines(file('SQL/query6.sql', 'r')), collapse = ' '))
  sqlStr 
  "--query 6select a6.column1, a6.column2, count(a6.column3) as counts --count the number of occurences in table 1from data.table a6 group by a6.column1"
  </code></pre>
  
  <p>when read into R.</p>