diff --git a/R/session.R b/R/session.R index 62c822c31..2a29550e8 100644 --- a/R/session.R +++ b/R/session.R @@ -63,9 +63,21 @@ is_installed <- function(pkg, ..., version = NULL, compare = NULL) { check_dots_empty0(...) + # Fast path. Note that if `version` is supplied, this always falls through to the + # more expensive check. + if (is.null(version)) { + loaded <- lapply(pkg, function(x) { + is.character(x) && nzchar(x) && is.environment(.getNamespace(x)) + }) + if (all(as.logical(loaded))) { + return(TRUE) + } + } + info <- pkg_version_info(pkg, version = version, compare = compare) all(detect_installed(info)) } + detect_installed <- function(info) { # Internal mechanism for unit tests hook <- peek_option("rlang:::is_installed_hook")