On Wed, 15 Aug 2001, Jan de Leeuw wrote:
> Is it true that append=T does not work in assignTable() in RMySQL ?
> More specifically: I cannot append a data.frame to an existing table
> in a MySQL database, although I can use the same data.frame to
> create a new table.
> Even more specifically:
> > assignTable(con,"employee",dita,append=T)
> Error in execStatement.MySQLConnection(con, statement, ...) :
> RS-DBI driver: (could not run statement: Table 'employee'
> already exists)
> [1] FALSE
Well, appending is implemented in RMySQL_0.4-2.tar.gz
but a look at
the Code
in R/All.R in that package line 701 revealed that it ALWAYS tries to
create a table
with name=<whatevername>
[snip] line 685:
sql1 <- paste("create table ", name, "\n(\n\t",
sep="")
sql2 <- paste(paste(names(field.types), field.types),
collapse=",\n\t")
sql3 <- "\n)\n"
sql <- paste(sql1, sql2, sql3, collapse="")
[.....] line 701:
rs <- try(dbExecStatement(new.con, sql))
if(inherits(rs, "Error") || inherits(rs,"try-error")){
return(F)
} else close(rs)
[snip]
so sql, which will try to create a new table, is tried, and MySQL
fails, because the tabel already exits
I put these lines 701-.. in an if-clause
if(!append){
rs <- try(dbExecStatement(new.con, sql))
if(inherits(rs, "Error") || inherits(rs,"try-error")){
return(F)
} else close(rs)
}
and once I installed the RMySQL package
appending/overwriting a dataframe to existing tables workes for me
> version
_
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 1
minor 2.0
year 2000
month 12
day 15
language R
***********************************************************************
Jens Nieschulze
Institute for Forest Biometrics & Phone: ++49-551-39-12107
Applied Computer Science Fax : ++49-551-39-3465
Buesgenweg 4
37077 Goettingen E-mail: jniesch at uni-forst.gwdg.de
GERMANY http://www.uni-forst.gwdg.de/~jniesch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._