Skip to content

Commit

Permalink
https://github.com/easystats/modelbased/issues/110
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 2, 2021
1 parent b756d35 commit 35722af
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# insight 0.14.2

## Changes to functions

* `check_if_installed()` gains a `minimum_version` argument, to check if an
installed package is not older than the specified version number.

## Bug fixes

* Fixed issue in `model_info()` with `stan_polr()` models.
Expand Down
20 changes: 16 additions & 4 deletions R/check_if_installed.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,41 @@
#' generic description.
#' @param stop Logical that decides whether the function should stop if the
#' needed package is not installed.
#' @param minimum_version String, representing the minimum package version that
#' is required. If \code{NULL}, no check for minimum version is done.
#' @param ... Currently ignored
#'
#' @examples
#' \dontrun{
#' check_if_installed("inexistent_package")
#' check_if_installed("insight")
#' check_if_installed("insight", minimum_version = "99.8.7")
#' }
#'
#' @export

check_if_installed <- function(package,
reason = "for this function to work",
stop = TRUE,
minimum_version = NULL,
...) {
# does it need to be displayed?
is_installed <- requireNamespace(package, quietly = TRUE)
if (!is_installed) {
# prepare the message
message <- paste0(
message <- format_message(paste0(
"Package '", package, "' is required ", reason, ".\n",
"Please install it by running install.packages('", package, "')."
)
))

if (stop) stop(message, call. = FALSE) else warning(message, call. = FALSE)
} else if (!is.null(minimum_version) && utils::packageVersion(package) < package_version(minimum_version)) {
# prepare the message
message <- format_message(paste0(
"Package '", package, "' is installed, but package version '", minimum_version,"' is required ", reason, ".\n",
"Please update the package by running install.packages('", package, "')."
))

if (stop) stop(message, call. = FALSE) else warning(message, call. = FALSE)
}

invisible(is_installed)
}
10 changes: 7 additions & 3 deletions man/check_if_installed.Rd

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

36 changes: 20 additions & 16 deletions man/data_to_long.Rd

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

0 comments on commit 35722af

Please sign in to comment.