dbWriteTable(..., append = T) is overwritng in R

AVSuresh picture AVSuresh · Jul 30, 2012 · Viewed 13.2k times · Source

I am using RJDBC for accessing MySQL from R. Earlier I used to work with RMySQL which is not available for R 2.15. There were so many discussions around SO but still I couldn't able to use RMySQL package in R 2.15 so switched to RJDBC.

When I'm using dbWriteTable(..., append = T) command for appending records into MySQL table it is simply overwriting, please see the code below.

setting environment variable for MySQL server

Sys.setenv(MYSQL_HOME='C:/Program Files (x86)/MySQL/MySQL Server 5.1')

library(RJDBC)

MySQL connection

drv <- JDBC("com.mysql.jdbc.Driver","mysql-connector-java-5.0.5.jar", "`")
conn <- dbConnect(drv, "Retail", user="root", password="abc")
..................
..................
..................
dbWriteTable(conn, "Customer_Tbl", x, row.names=F,append = T)

Customer_Tbl is overwriting everytime instead of appending.

Can somebody help in how to tackle this issue?

Thanks Suresh

Answer

Annie picture Annie · Jan 20, 2014

You need to use overwrite=FALSE, following sample code:

dbWriteTable(connection, name=tableName, value=rows , append=T, row.names=F, overwrite=F);