Skip to content

Commit

Permalink
Use find.package() for more precise skip note
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Oct 24, 2024
1 parent 350e0a8 commit a748736
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/skip.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ skip_if <- function(condition, message = NULL) {
#' @param minimum_version Minimum required version for the package
#' @rdname skip
skip_if_not_installed <- function(pkg, minimum_version = NULL) {
# most common case: it's not installed
res <- tryCatch(find.package(pkg), error = identity)
if (inherits(res, "error")) {
skip(paste0("{", pkg, "} is not installed"))
}
# rarer: it's installed, but fails to load
if (!requireNamespace(pkg, quietly = TRUE)) {
skip(paste0("{", pkg, "} cannot be loaded"))
}
Expand Down

0 comments on commit a748736

Please sign in to comment.