sink()
is useful for logging errors to file without having to wrap everything in tryCatch
's. However, instead of logging to a file, I would like to log to a (SQLite) database table. Is this possible?
More generally, with sink()
, how can I specify my own function to handle the actual write process?
sink
diverts to aconnection
, not a file. To sink to a DB table, you simply need to use a connection that writes to a database table instead.This then opens a database connection to the host. Then you do:
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.