4

I'm trying to add rows to a SQLite data base using dplyr. Based on StatSandwich's answer to this post I would have thought that the following may work:

library(dplyr)
data1 <- filter(mtcars, cyl == 6)
data2 <- filter(mtcars, cyl == 4)

my_db <- src_sqlite(path="Test.DB", create = TRUE)
copy_to(my_db, data1, temporary = FALSE)
db_insert_into(my_db, table=data1, values=data2) # Error

However, I get the following error:

Error in UseMethod("db_insert_into") : no applicable method for 'db_insert_into' applied to an object of class "c('src_sqlite', 'src_sql', 'src')"

Would anyone be able to point out what I'm doing wrong?

Thanks, Philipp

Community
  • 1
  • 1
PMaier
  • 592
  • 7
  • 19
  • hi, your attempt differs from @StatSandwich by quite a bit...try copy_to(my_db, data1, "mtcarsTable", temporary = FALSE); db_insert_into(my_db$con, table="mtcarsTable", values=data2) # – chinsoon12 Apr 13 '16 at 01:38
  • 3
    or just to fix that error you should use: db_insert_into(my_db$con, table="data1", values=data2) – chinsoon12 Apr 13 '16 at 01:42
  • Works! Thank you so much. – PMaier Apr 13 '16 at 01:46

0 Answers0