When developing package using DBI extension (e.g. RJDBC, RSQLite) which package should I refer to?
connect_my_db <- function() DBI::dbConnect(RSQLite::SQLite(), "my_db.sqlite")
or
connect_my_db <- function() RSQLite::dbConnect(RSQLite::SQLite(), "my_db.sqlite")
?
First method force me to use DBI in Imports, so I prefer second one. But on other side I should call virtual function and let R to decide what to call.
The DBI spec do require all backends to re-export all of DBI's methods, so both notations (RSQLite::dbConnect()
vs. DBI::dbConnect()
) are identical for all practical purposes:
identical(DBI::dbConnect, RSQLite::dbConnect)
#> [1] TRUE
The DBI::
notation expresses that you're using a DBI function, but if your package only uses RSQLite
it seems fine to use that prefix from a code style point of view.