2017-09-25 30 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,包裝作者。