sink
diverts to a connection
, not a file. To sink to a DB table, you simply need to use a connection that writes to a database table instead.
dbc = dbconnection(host="mysql.example.com", table="logs",field="logtext")
This then opens a database connection to the host. Then you do:
sink(dbc)
print("stuff")
sink()
Then the database connection code does INSERT INTO logs (time,logtext) VALUES ("12-Jan-2001" "R output comes here") - if you want to do datestamped log entries, for example.
So all you need to do is write that function that creates a connection
to the database. Which I think has to be done at the C level - I don't know if you can create new connection types in pure R. Good luck with that.