2017-09-25 31 views
0

考虑使用dplyr将数据添加到表中,我看到https://stackoverflow.com/a/26784801/1653571,但文档说db_insert_table()已被弃用。不能使用dplyr将数据追加到sqlite3 db_write_table()

?db_insert_into() 

... 
db_create_table() and db_insert_into() have been deprecated in favour of db_write_table(). 
... 

我试图用非弃用db_write_table()代替,但既没有在append=选项失败:

require(dplyr) 

my_db <- src_sqlite("my_db.sqlite3", create = TRUE)     # create src 
copy_to(my_db, iris, "my_table", temporary = FALSE)     # create table 
newdf = iris               # create new data 

db_write_table(con = my_db$con, table = "my_table", values = newdf) # insert into 
# Error: Table `my_table` exists in database, and both overwrite and append are FALSE 

db_write_table(con = my_db$con, table = "my_table", values = newdf,append=True) # insert into 
# Error: Table `my_table` exists in database, and both overwrite and append are FALSE 

如果一个能够与db_write_table()追加数据?

https://github.com/tidyverse/dplyr/issues/3120

回答

0

看到没,你不应该使用db_write_table()而不是db_insert_table(),因为它不能跨后端一概而论。

而且你不应该使用纯版本而不是相关的DBI :::版本,因为tidyverse帮助器函数是供内部使用的,而且没有设计为足够强大以供用户使用。请参阅https://github.com/tidyverse/dplyr/issues/3120#issuecomment-339034612的讨论:

其实,我认为你根本不应该使用这些函数。尽管如此,这些并不是面向用户的功能。您应该直接调用DBI函数。
- Hadley Wickham,包装作者。