diff --git a/R/bistro.R b/R/bistro.R index ee4d91a..a5d876b 100644 --- a/R/bistro.R +++ b/R/bistro.R @@ -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, diff --git a/R/identify_matches.R b/R/identify_matches.R index d60f4b7..6d0883a 100644 --- a/R/identify_matches.R +++ b/R/identify_matches.R @@ -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) diff --git a/R/utils.R b/R/utils.R index 89441c2..5634e02 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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.") + } +} diff --git a/man/check_pkg_version.Rd b/man/check_pkg_version.Rd new file mode 100644 index 0000000..d9d4bda --- /dev/null +++ b/man/check_pkg_version.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{check_pkg_version} +\alias{check_pkg_version} +\title{Check package version} +\usage{ +check_pkg_version(pkg, curr_version, version) +} +\arguments{ +\item{pkg}{package to test} + +\item{curr_version}{current package version} + +\item{version}{required package version} +} +\value{ +nothing or error if package version too old +} +\description{ +Check package version +} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index da50b77..0b32299 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -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.") +})