I am using sqldf
to train some r-users in SQL. Loading RPostgreSQL
or RH2
before loading sqldf
will change the default SQL used by sqldf
. This works fine with h2, but every time I load RPostgreSQL
, R will crash on first attempted query. I want to make sqldf
work with RPostgreSQL
to enable use of date functions which are lacking in SQLite
and h2
.
# packages
library(tidyverse)
# library(RH2) # comment out this row or the next to determine default SQL for sqldf
library(RPostgreSQL)
library(sqldf)
Output confirms that "sqldf will default to using PostgreSQL"
Create some data:
set.seed(42)
N <- 1e6
sales <- tibble(
buyer_id = 1:N/100,
sales_date = sample(seq(as.Date('2018/01/01'), as.Date('2021/01/01'), by="day"), N, replace = TRUE),
sales_amount = rpois(N, 200)
)
Crash R:
sqldf("
select
max(sales_date)
from sales
")
"R Session Aborted
R encountered a fatal error
The session was terminated"