title: Can dplyr function work connected with SQL server?
body: <p>I have a table in SQL server database, and I want to manipulate this table with dbplyr/dplyr in R packages.</p>
  <pre><code>library(odbc)
  library(DBI)
  library(tidyverse)
  
  con &lt;- DBI::dbConnect(odbc::odbc(),
                        Driver    = &quot;SQL Server&quot;, 
                        Server    = &quot;xx.xxx.xxx.xxx&quot;,
                        Database  = &quot;stock&quot;,
                        UID       = &quot;userid&quot;,
                        PWD       = &quot;userpassword&quot;)
  
  startday = 20150101
  day = tbl(con, in_schema(&quot;dbo&quot;, &quot;LogDay&quot;)) 
  </code></pre>
  <p><a href="https://i.stack.imgur.com/tcV6X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tcV6X.png" alt="enter image description here" /></a></p>
  <p>I tried this simple dplyr function after connecting to remote database, but only to fail with error messages.</p>
  <pre><code>day %&gt;% 
    mutate(ovnprofit = ifelse(stockCode == lead(stockCode,1),lead(priceOpen,1)/priceClose, NA)) %&gt;% 
    select(logDate,stockCode, ovnprofit)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/UA3pL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UA3pL.png" alt="enter image description here" /></a></p>
  <p>How can I solve this problem?</p>
  <p>p.s. When I apply dplyr function after transforming 'day' into tibble first, it works. However, I want to apply dplyr function directly, not transforming into tibble because it's to time consuming and memory intensive.</p>