mllg / checkmate

Fast and versatile argument checks
https://mllg.github.io/checkmate/
Other
261 stars 30 forks source link

add namespace checks #176

Open maxheld83 opened 4 years ago

maxheld83 commented 4 years ago

I frequently add a helper like this one (from the r-pkgs book) to my packages and scripts to optionally respond to our error out on missing Suggests: dependencies:

#' Error out on unavailable optional pkgs
#' @inheritParams requireNamespace
#' @noRd
requireNamespace2 <- function(x) {
  if (!requireNamespace(x, quietly = TRUE)) {
    stop(
      paste(
        x,
        "needed for this function to work.",
        "Please install it."
      ),
      call. = FALSE
    )
  }
}

It's small enough I guess, but I'd love to be able to just checkmate::assert_pkg(pkg = "foo") in my code without always adding the same helper function.

Any chance you might be interested in such an addition?

I know it sits a bit weirdly with the rest of the pkg, because that's mostly about R objects, not side effects (though, arguably checkmate::assert_directory() is pretty similar).

Don't think it would add dependencies, and I'd just love using the amazing checkmate signature for another thing. Saves mental load.

I'd be happy to add a PR for this.