Last active
August 29, 2015 13:57
-
-
Save hadley/9643549 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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