mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 18:06:12 +01:00
more robust install check
This commit is contained in:
parent
76bcd3528c
commit
85ed7ea5f0
@ -345,23 +345,17 @@ is_valid_regex <- function(x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop_ifnot_installed <- function(package) {
|
stop_ifnot_installed <- function(package) {
|
||||||
# no "utils::installed.packages()" since it requires non-staged install since R 3.6.0
|
installed <- vapply(FUN.VALUE = logical(1), package, requireNamespace, quietly = TRUE)
|
||||||
# https://developer.r-project.org/Blog/public/2019/02/14/staged-install/index.html
|
if (any(!installed) && any(package == "rstudioapi")) {
|
||||||
vapply(FUN.VALUE = character(1), package, function(pkg) {
|
stop("This function only works in RStudio when using R >= 3.2.", call. = FALSE)
|
||||||
tryCatch(get(".packageName", envir = asNamespace(pkg)),
|
} else if (any(!installed)) {
|
||||||
error = function(e) {
|
stop("This requires the ", vector_and(package[!installed]), " package.",
|
||||||
if (pkg == "rstudioapi") {
|
"\nTry to install with install.packages().",
|
||||||
stop("This function only works in RStudio when using R >= 3.2.", call. = FALSE)
|
call. = FALSE
|
||||||
} else if (pkg != "base") {
|
)
|
||||||
stop("This requires the '", pkg, "' package.",
|
} else {
|
||||||
"\nTry to install it with: install.packages(\"", pkg, "\")",
|
return(invisible())
|
||||||
call. = FALSE
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
return(invisible())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_is_available <- function(pkg, also_load = TRUE, min_version = NULL) {
|
pkg_is_available <- function(pkg, also_load = TRUE, min_version = NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user