feature request: has_package()
This idea follows from the "Suggests" section of the R-pkgs book, where you provide the code:
if (!requireNamespace("pkg", quietly = TRUE)) {
stop("Package \"pkg\" needed for this function to work. Please install it.",
call. = FALSE)
}
Could this be useful as a new assertion,has_package()?
assertthat::has_package("dplyr")
I'd be happy to make the PR if you think this might be useful. If so, some questions:
- Name:
has_package(),has_packages(), other? - Should the argument be
...as unnamed, orpackageswhich would be a character-vector of package names, or other?
Upon further reflection, I see has_package() would not be the right name. What I am proposing is more like assert_package().
(has_package() would be a vectorized wrapper to requireNamespace())
There are not any assert_ functions beyond assert_that(), so I can see where this might not be the right way to go about this.
I have developed this function, now called assert_packages(), in one of my packages: https://github.com/vegawidget/vegawidget/blob/cran-release-0.1.0/R/utils-package.R
I have found it useful, so I'd be happy to make a PR here if you like.
Sure, a PR would be great