I've added a function to a package that performs a simple operation on a dbplyr database connection. In interactive testing, I create a dummy database with memdb_frame
like this:
x <- memdb_frame(caseID = 1, DOB = 2, Other = 3)
And then the function performs its job on x
. But when I try to create a database the same way in the package's testthat
tests, I get an error:
Error in `(function (cond)
.Internal(C_tryCatchHelper(addr, 1L, cond)))(structure(list(message = "there is no package called 'RSQLite'",
call = loadNamespace(x), package = "RSQLite", lib.loc = NULL), class = c("packageNotFoundError",
"error", "condition")))`: error in evaluating the argument 'drv' in selecting a method for function 'dbConnect': there is no package called 'RSQLite'
I think earlier in debugging, it was giving an error like this for RMySQL, which I might have fixed by adding RMySQL to the package's Suggests list.
My Suggests list is currently:
Suggests:
dbplyr,
knitr,
rmarkdown,
RMySQL,
sf,
testthat (>= 3.0.0),
tibble,
tidygraph
And traceback includes:
2. │ ├─dplyr::copy_to(src_memdb(), tibble(...), name = .name)
3. │ └─dbplyr::src_memdb()
4. │ ├─dbplyr:::cache_computation(...)
5. │ │ └─base::force(computation)
6. │ ├─dbplyr::src_dbi(...)
7. │ │ └─base::force(con)
8. │ └─DBI::dbConnect(RSQLite::SQLite(), ":memory:", create = TRUE)
Edit the package's DESCRIPTION
file to include RMySQL
in Suggests. Then the above test runs correctly. Including RSQLite
is not necessary.