With RODBC, there were functions like sqlUpdate(channel, dat, ...)
that allowed you pass dat = data.frame(...)
instead of having to construct your own SQL string.
However, with R's DBI, all I see are functions like dbSendQuery(conn, statement, ...)
which only take a string statement
and gives no opportunity to specify a data.frame
directly.
So how to UPDATE
using a data.frame
with DBI?
Really late, my answer, but maybe still helpful...
There is no single function (I know) in the DBI/odbc package but you can replicate the update behavior using a prepared update statement (which should work faster than RODBC's
sqlUpdate
since it sends the parameter values as a batch to the SQL server:This works only if you have a primary key which I created in the above example by using the row names which are a unique number increased by one for each row...
For more information about the
odbc
package I have used in the DBIdbConnect
statement see: https://github.com/rstats-db/odbc