Is it possible to insert (add) a row to a SQLite db table using dplyr package?

后端 未结 4 1969
时光说笑
时光说笑 2020-12-09 08:20

I am new to the database connection capabilities of dplyr package, but I am very interested in using it for an SQLite connection. I followed this tutorial and created an SQL

4条回答
  •  醉梦人生
    2020-12-09 09:05

    In this newsgroup. Hadley explained the purpose of the function dplyr::copy_to(). It is intended to create temporary test tables. The email exchange ends by suggesting to use RMySQL::dbWriteTable() to append data to an existing table. The same applies to SQLite databases, as explained in the accepted answer above.

    To append a data frame dtf which has the same column names as an existing database table, I used:

    library(RMySQL)
    DB <- dbConnect(MySQL(), user="usename", host="localhost",
                       password="***", dbname="dbname")
    dbWriteTable(DB, "tablename", dtf, append=TRUE, row.names = FALSE)
    

提交回复
热议问题