I normally use filter
with grepl
in dplyr, but when using dbplyr
. I get an error that grepl is not a recognized function. My guess is that it can't translate to SQL server. What is a way around this with dbplyr
Here is a reproducible example
library(dbplyr)
library(nycflights13)
## Working chunk
con <-DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(con, "flights", flights)
DBI::dbGetQuery(con, "SELECT origin, flight
FROM flights WHERE origin like '%jf%'")
## End working chunk
## The below code does not work
flights <- tbl(con,"flights")
flights %>%
select(origin, flight) %>%
filter(grepl('jf', origin))
I found the solution from this answer effective.
Here is the code that works for your case:
dplyr::tbl(con, "flights") %>%
filter(origin %like% '%jf%') %>%
collect()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With