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

后端 未结 4 2005
时光说笑
时光说笑 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:18

    You can perform SQL operations on a database/table created via dplyr, but you have to revert to RSQLite/DBI calls and change how you made the database/table:

    library(dplyr)
    
    my_db <- src_sqlite("my_db.sqlite3", create=TRUE) 
    copy_to(my_db, iris, "my_table", temporary=FALSE) # need to set temporary to FALSE
    
    # grab the db connection from the object created by src_sqlite
    # and issue the INSERT That way
    
    res <- dbSendQuery(my_db$con, 
                       'INSERT INTO my_table VALUES (9.9, 9.9, 9.9, 9.9, "new")')
    

提交回复
热议问题