I'm trying to more seamlessly integrate my use of R and SQL. The good news is I have the connection from R to db2 working well and have been using the RJDBC package to do so.
I've also been using the dbGetQuery() function that includes the sql query. For very simple queries this is all good.
cr_tb1 <- dbGetQuery(conn, "SELECT * FROM LWFILES001.EVETRNPF LIMIT 100")
However, I want to keep complex sql queries out of the R code and have them saved as a separate .sql that the function can reference.
I've loaded the squr library https://github.com/smbache/squr to facilitate this reference. So, I've tried something like this, but get an error.
library(RJDBC)
library(squr)
drv <- JDBC("com.ibm.as400.access.AS400JDBCDriver",
"C:/temp/jt400.jar",
identifier.quote="`")
conn <- dbConnect(drv, "jdbc:as400://lwsi.XXXX.local/XXXXXX", "username", "password")
case_rate_query <- sq_file("SQL//test.sql")
cr_tb1 <- dbGetQuery(conn, case_rate_query)
Here is the error:
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘dbGetQuery’ for signature ‘"JDBCConnection", "sq"’
Thank You for your help.