Skip to content

Instantly share code, notes, and snippets.

@hadley
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadley/9643549 to your computer and use it in GitHub Desktop.
Save hadley/9643549 to your computer and use it in GitHub Desktop.
is_installed <- function(pkg, version = NULL) {
system.file(package = pkg) != "" && version_ok(pkg, version)
}
version_ok <- function(pkg, version = NULL) {
if (is.null(version)) return(TRUE)
pkgVersion(pkg) >= version
}
check_installed <- function(pkg, version = NULL) {
if (!is_installed(pkg)) {
stop("Please install ", pkg, call. = FALSE)
}
if (!version_ok(pkg, version)) {
stop("Need at least version ", version, " of ", pkg, ". ",
"Currently running ", packageVersion(pkg), call. = FALSE)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment