Why am I getting an "unused argument" error when using R database query params?

618 Views Asked by At

I'm absolutely baffled by this bug that seems to have appeared. I need to use the params parameter in a database query, but every time I do, I get an "unused argument" error. I've checked the docs and even old code of mine that does the same thing and I can't tell what's going wrong now.

So for example, this works fine:

yearIdsQuery <- "SELECT * FROM dimTime WHERE year = 1975"
timeIds.df <- dbGetQuery(mysql_con, yearIdsQuery)

But this throws the error:

yearIdsQuery <- "SELECT * FROM dimTime WHERE year = ?"
timeIds.df <- dbGetQuery(mysql_con, yearIdsQuery, params = list(1975))

I'm running (I believe) R 4.2.2 and using the RMySQL library (which I believe itself uses the DBI library) to connect to a MySQL database on Amazon Web Services. I'm working in RStudio on an M1 Mac running Big Sur 11.6.

I would swear I've used identical code successfully in the last few days, but I'm quite new to R, so I'm not certain if I've done something wrong or there's an actual glitch occurring. I tried using dbExecute instead of dbGetQuery, and even tried dbBind/dbFetch, but I get the same error regardless. I've also tried making the element in the params list a string rather than a number.

Any insights or advice would be much appreciated. Thank you!

EDIT 1: Here's the entire error message.

Error in .local(conn, statement, ...) : unused argument (params = list(1975))

EDIT 2: The results of traceback():

5: dbSendQuery(conn, statement, ...)
4: dbSendQuery(conn, statement, ...)
3: .local(conn, statement, ...)
2: dbGetQuery(mysql_con, yearIdsQuery, params = list(1975))
1: dbGetQuery(mysql_con, yearIdsQuery, params = list(1975))
0

There are 0 best solutions below