presagia-analytics / ctrialsgov

Query Data from ClinicalTrials.gov
https://presagia-analytics.github.io/ctrialsgov/
Other
13 stars 3 forks source link

Handling `dbDisconnect()` warning #16

Closed kaneplusplus closed 2 years ago

kaneplusplus commented 2 years ago

When creating RMarkdown documents, I tend to get the following error message, sometimes multiple times:

1: Connection is garbage-collected, use dbDisconnect() to avoid this.
2: Database is garbage-collected, use dbDisconnect(con, shutdown=TRUE) or duckdb::duckdb_shutdown(drv) to avoid this.

I think this happens because we don't explicitly close the database connection. As a resolution, I'd like to propose reg.finalizer() is called on the .volatiles environment and explicitly calls either dbDisconnect() or duckdb_shutdown().