Skip to content

Commit

Permalink
Add check for recent enough version of tidyr package resolves #2
Browse files Browse the repository at this point in the history
  • Loading branch information
zenalapp committed Nov 17, 2023
1 parent 735dd46 commit 3437aaf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/bistro.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ bistro <-
seed = 1,
time_limit = 3,
return_lrs = FALSE) {
check_pkg_version('tidyr', utils::packageVersion('tidyr'), '1.3.0')
check_bistro_inputs(
bloodmeal_profiles,
human_profiles,
Expand Down
1 change: 1 addition & 0 deletions R/identify_matches.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#' @inheritParams calc_one_log10_lr
#' @keywords internal
identify_one_match_set <- function(log10_lrs, bloodmeal_id) {
check_pkg_version('tidyr', utils::packageVersion('tidyr'), '1.3.0')
bm_id <- bloodmeal_id
log10_lrs <- log10_lrs |>
dplyr::filter(bloodmeal_id == bm_id)
Expand Down
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@ utils::globalVariables(
ignore_unused_imports <- function() {
codetools::checkUsage
}

#' Check package version
#'
#' @param pkg package to test
#' @param curr_version current package version
#' @param version required package version
#'
#' @return nothing or error if package version too old
check_pkg_version <- function(pkg, curr_version, version){
vers <- utils::compareVersion(as.character(curr_version), version)
if(vers == -1){
stop("The ", pkg, " package is version ", curr_version, " but must be >= ", version, ". Please update the package to use this function.")
}
}
21 changes: 21 additions & 0 deletions man/check_pkg_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
test_that("ignore_unused_imports works", {
expect_no_error(ignore_unused_imports())
})

test_that("check_pkg_version works", {
expect_no_error(check_pkg_version('tidyr', '1.1.2', '1.1.1'))
expect_no_error(check_pkg_version('tidyr', '1.1.1', '1.1.1'))
expect_error(check_pkg_version('tidyr', '1.1.1', '1.1.2'),
"The tidyr package is version 1.1.1 but must be >= 1.1.2. Please update the package to use this function.")
})

0 comments on commit 3437aaf

Please sign in to comment.