inbo / n2khab

R package with preprocessing functions and standard reference data for Flemish Natura 2000 (N2K) habitat (HAB) analyses
https://inbo.github.io/n2khab
GNU General Public License v3.0
2 stars 1 forks source link

Add internal function require_pkgs() and implement #128

Closed florisvdh closed 3 years ago

florisvdh commented 3 years ago

This simplifies things as follows:

@@ -430,11 +426,7 @@ read_GRTSmh_base4frac <-
     function(file = file.path(fileman_up("n2khab_data"),
                               "20_processed/GRTSmh_base4frac/GRTSmh_base4frac.tif")) {

-        if (!requireNamespace("raster", quietly = TRUE)) {
-            stop("Package \"raster\" is needed when using this function. ",
-                 "Please install it.",
-                 call. = FALSE)
-        }
+        require_pkgs("raster")

         r <- raster::raster(file)
         raster::crs(r) <- "EPSG:31370"

Behaviour:

> require_pkgs(c("a", "base", "b", "c"))
Error: Multiple packages needed for this function are missing.
Please install as follows: install.packages(c("a", "b", "c"))
> require_pkgs("targets")
Error: A package needed for this function is missing.
Please install as follows: install.packages("targets")