Skip to content

Commit

Permalink
Tweak dependency handling
Browse files Browse the repository at this point in the history
* Bump required version of DBI. Fixes #178.
* Message if dbplyr is old. Fixes #179 (as much as possible)
  • Loading branch information
hadley committed Feb 13, 2024
1 parent 11f2372 commit ee2c676
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ Depends:
methods,
R (>= 3.6.0)
Imports:
DBI,
DBI (>= 1.2.1),
later (>= 1.0.0),
R6,
rlang (>= 1.0.0)
Suggests:
covr,
dbplyr (>= 2.0.0),
dbplyr (>= 2.4.0),
dplyr,
knitr,
rmarkdown,
Expand All @@ -39,4 +39,4 @@ Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ import(rlang)
importFrom(DBI,dbBreak)
importFrom(R6,R6Class)
importFrom(later,later)
importFrom(utils,packageVersion)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pool (development version)

* Now requires DBI 1.2.0 (#178) and messages if you're using an old dbplyr
(#179).

# pool 1.0.2

* No longer depends on the withr package, by instead requiring R 3.6.
Expand Down
15 changes: 15 additions & 0 deletions R/dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ dbplyr_register_methods <- function() {

# Wrappers inspect formals so can only be executed if dbplyr is available
on_package_load("dbplyr", {
check_dbplyr()

dbplyr_s3_register <- function(fun_name) {
s3_register(paste0("dbplyr::", fun_name), "Pool", dbplyr_wrap(fun_name))
}
Expand All @@ -95,6 +97,19 @@ dbplyr_register_methods <- function() {
})
}

check_dbplyr <- function() {
if (packageVersion("dbplyr") < "2.4.0") {
inform(
c(
"!" = "Pool works best with dbplyr 2.4.0 or greater.",
i = paste0("You have dbplyr ", packageVersion("dbplyr"), "."),
i = "Please consider upgrading."
),
class = c("packageStartupMessage", "simpleMessage")
)
}
}

dbplyr_wrap <- function(fun_name) {
fun <- utils::getFromNamespace(fun_name, "dbplyr")
args <- formals(fun)
Expand Down
5 changes: 5 additions & 0 deletions R/pool-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
#' @importFrom later later
#' @import rlang
NULL

## usethis namespace: start
#' @importFrom utils packageVersion
## usethis namespace: end
NULL
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/dbplyr.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@
}
<environment: namespace:pool>

# warns if dbplyr is old

Code
check_dbplyr()
Message
! Pool works best with dbplyr 2.4.0 or greater.
i You have dbplyr 1.0.0.
i Please consider upgrading.

12 changes: 12 additions & 0 deletions tests/testthat/test-dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ test_that("wrapper looks good", {
dbplyr_wrap("db_compute")
})
})

test_that("warns if dbplyr is old", {
local_mocked_bindings(packageVersion = function(...) "1.0.0")
expect_snapshot({
check_dbplyr()
})

cnd_dplyr <- class(catch_cnd(check_dbplyr()))
cnd_startup <- class(catch_cnd(packageStartupMessage("hi")))
cnd_startup <- c(cnd_startup[1:2], "rlang_message", cnd_startup[-(1:2)])
expect_equal(cnd_dplyr, cnd_startup)
})

0 comments on commit ee2c676

Please sign in to comment.