title: How to read the contents of an .sql file into an R script to run a query?
body: <p>I have tried the <code>readLines</code> and the <code>read.csv</code> functions but then don't work.</p>
  
  <p>Here is the contents of the <code>my_script.sql</code> file:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees
  WHERE HireDate &gt;= '1-july-1993'
  </code></pre>
  
  <p>and it is saved on my Desktop.</p>
  
  <p>Now I want to run this query from my R script. Here is what I have:</p>
  
  <pre class="lang-r prettyprint-override"><code>conn = connectDb()
  
  fileName &lt;- "C:\\Users\\me\\Desktop\\my_script.sql"
  query &lt;- readChar(fileName, file.info(fileName)$size)
  
  query &lt;- gsub("\r", " ", query)
  query &lt;- gsub("\n", " ", query)
  query &lt;- gsub("ï»¿", " ", query)
  
  recordSet &lt;- dbSendQuery(conn, query)
  rate &lt;- fetch(recordSet, n = -1)
  
  print(rate)
  disconnectDb(conn)
  </code></pre>
  
  <p>And I am not getting anything back in this case. What can I try?</p>