trendbreaker
trendbreaker copied to clipboard
Check via requireNamespace if optional packages are loaded
Before using them. Otherwise trigger an error. For brms
and MASS
.
Something like the following:
glustop <- function(..., .sep = "", .envir = parent.frame()) {
stop(glue::glue(..., .sep = .sep, .envir = .envir), call. = FALSE)
}
check_suggests <- function(package) {
if (!requireNamespace(package, quietly = TRUE)) {
glustop("Suggested package '{package}' not present.")
}
}
check_suggests("MASS")
check_suggests("treesarecool")
#> Error: Suggested package 'treesarecool' not present.
Created on 2020-08-04 by the reprex package (v0.3.0)
Yeah. Although maybe good to drop the glue
dependency :)
will be closed by trending (