title: R: run multiple line sql from text file
body: <p>In R, how can I import the contents of a multiline text file (containing SQL) into multiple lines of SQL?</p>
  
  <p>I've studied <a href="https://stackoverflow.com/questions/2003663/r-language-import-multiline-sql-query-to-single-string">Import multiline SQL query to single string</a> and managed to get a simple sql script working. However, when SQL demands a new line (ie when you add a SELECT statement) it doesn't work when you put all lines of sql script in one line. </p>
  
  <p>The sql .txt file looks like:</p>
  
  <pre><code>CREATE TABLE #Countries (Country varchar(255), Region varchar(255)) 
  INSERT INTO #Countries  VALUES ('China', 'EM') 
  SELECT * FROM #Countries
  </code></pre>
  
  <p>The R code looks like:</p>
  
  <pre><code>fileconn&lt;-file("R/sql.txt","r")            
  sqlString&lt;-readLines(fileconn)           
  sqlString&lt;-paste(sqlString,collapse="","") 
  sqlconn &lt;- odbcDriverConnect(connection = ....)
  sqlQuery(sqlconn,sqlString)
  </code></pre>
  
  <p>I've tried CAT and GSUB as well, but I've got the feeling that the problem occors when the third statement follows the second in one line.</p>
  
  <p>Can anyone help me with this problem? Many thanks.</p>