checkmate icon indicating copy to clipboard operation
checkmate copied to clipboard

add namespace checks

Open maxheld83 opened this issue 5 years ago • 0 comments

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.

maxheld83 avatar Mar 12 '20 13:03 maxheld83