0
votes

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 ...

1
Please edit to make note of where functions come from. - camille
That function typically takes an object as the first in its signature, not character. For example RPostgres::dbWriteTable has a signature of c("PqConnection", "character", "data.frame"). This suggests that your conn is not what it should be. - r2evans
Thank you! I need to set a connection object instead of a 'character' - Matheus Silva
@MatheusSilva could you put that solution in an answer? - timothy.s.lau

1 Answers

0
votes

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!