Matheus Silva
Matheus Silva

Reputation: 9

Error in R: unable to find an inherited method for function ‘dbWriteTable’

I'm trying to write a table in a db using R and I got this error:

Script:

try(
silent = TRUE, {
dbWriteTable(conn, tableName, csvData, append = app, overwrite = !app)
dbDisconnect(conn)})

PS.: app <- FALSE

Error:

"Error in (function (classes, fdef, mtable) : \n unable to find an inherited method for function ‘dbWriteTable’ for signature ‘\"character\", \"character\", \"data.frame\"’\n" attr(,"class") [1] "try-error" attr(,"condition") \001NULL\001, skeleton = (function (conn, name, value, ...) stop("invalid call in method dispatch to 'dbWriteTable' (no ...

Upvotes: 0

Views: 2114

Answers (1)

stevec
stevec

Reputation: 52797

This happened to me because the object I was providing was not a data.frame (or tibble).

dbWriteTable(conn, tableName, csvData, append = app, overwrite = !app)

How I fixed it was to simply convert the object to a data.frame before calling dbWriteTable()

csvData <- as.data.frame(csvData)
dbWriteTable(conn, tableName, csvData, append = app, overwrite = !app)
#  It works!

Upvotes: 1

Related Questions