trendbreaker icon indicating copy to clipboard operation
trendbreaker copied to clipboard

Check via requireNamespace if optional packages are loaded

Open dirkschumacher opened this issue 4 years ago • 3 comments

Before using them. Otherwise trigger an error. For brms and MASS.

dirkschumacher avatar Jun 02 '20 20:06 dirkschumacher

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)

TimTaylor avatar Aug 04 '20 14:08 TimTaylor

Yeah. Although maybe good to drop the glue dependency :)

dirkschumacher avatar Aug 11 '20 07:08 dirkschumacher

will be closed by trending ( usage removed :) )

TimTaylor avatar Aug 12 '20 10:08 TimTaylor