From a69e1a0e55d8b5fbbdfd1cf752f1cd77aba7ad3b Mon Sep 17 00:00:00 2001 From: Brayden Nilson <45985474+B-Nilson@users.noreply.github.com> Date: Mon, 8 Dec 2025 22:32:54 +0000 Subject: [PATCH 1/2] replace requireNamespace with rlang::check_installed throughout --- R/color.R | 3 +-- R/mapshot.R | 4 ++-- R/ops.R | 9 +-------- R/print.R | 2 +- R/raster.R | 22 +++++----------------- R/watch.R | 8 +------- 6 files changed, 11 insertions(+), 37 deletions(-) diff --git a/R/color.R b/R/color.R index 363f2740..e8af068c 100644 --- a/R/color.R +++ b/R/color.R @@ -417,8 +417,7 @@ mapViewPalette <- function(name) { # setClassPalette <- function(simple.class) { # # pkgs <- c("viridis") -# avl <- sapply(pkgs, "requireNamespace", -# quietly = TRUE, USE.NAMES = FALSE) +# avl <- rlang::check_installed(pkgs) # # if (simple.class == "rst") { # diff --git a/R/mapshot.R b/R/mapshot.R index cc7f08da..611b2750 100644 --- a/R/mapshot.R +++ b/R/mapshot.R @@ -70,7 +70,7 @@ mapshot = function(x, "easyButton"), ...) { - stopifnot(requireNamespace("webshot", quietly = TRUE)) + rlang::check_installed("webshot") ## if both 'url' and 'file' are missing, throw an error avl_url = !is.null(url) @@ -219,7 +219,7 @@ mapshot2 = function(x, "control"), ...) { - stopifnot(requireNamespace("webshot2", quietly = TRUE)) + rlang::check_installed("webshot2") ## if both 'url' and 'file' are missing, throw an error avl_url = !is.null(url) diff --git a/R/ops.R b/R/ops.R index c88f0fb7..a7067c61 100644 --- a/R/ops.R +++ b/R/ops.R @@ -227,14 +227,7 @@ setMethod("|", function (e1, e2) { if (mapviewGetOption("platform") %in% c("leaflet")) { - - if (!requireNamespace("leaflet.extras2")) { - stop( - "\nPackage 'leaflet.extras2' is needed for the '|' operator to work.\n" - , "Install with install.packages('leaflet.extras2')" - , call. = FALSE - ) - } + rlang::check_installed("leaflet.extras2") e1_tile_idx = getCallEntryFromMap(e1@map, "addProviderTiles") if (length(e1_tile_idx) > 1) { diff --git a/R/print.R b/R/print.R index 121c0723..3c2df255 100644 --- a/R/print.R +++ b/R/print.R @@ -101,7 +101,7 @@ get_ide = function() { } is_rstudio = function() { - if (requireNamespace("rstudioapi", quietly = TRUE)) { + if (rlang::check_installed("rstudioapi")) { rstudioapi::isAvailable() && rstudioapi::versionInfo()$mode != "vscode" } else { FALSE diff --git a/R/raster.R b/R/raster.R index adb99a23..c71c0227 100644 --- a/R/raster.R +++ b/R/raster.R @@ -35,19 +35,10 @@ leafletRL = function(x, if (is.null(layer.name)) layer.name = makeLayerName(x, zcol = NULL) pkgs = c("leaflet", "raster", "magrittr") - tst = sapply(pkgs, "requireNamespace", - quietly = TRUE, USE.NAMES = FALSE) + rlang::check_installed(pkgs) if (native.crs) { - - if (!requireNamespace("plainview", quietly = TRUE)) { - stop( - paste("\nviewing rasters with native CRS requires package 'plainview'.\n", - "To install use install.packages('plainview')"), - call. = FALSE - ) - } - + rlang::check_installed("plainview") plainview::plainView(x, maxpixels = mapviewGetOption("plainview.maxpixels"), col.regions = col.regions, @@ -205,8 +196,7 @@ leafletRSB = function(x, ...) { pkgs = c("leaflet", "raster", "magrittr") - tst = sapply(pkgs, "requireNamespace", - quietly = TRUE, USE.NAMES = FALSE) + rlang::check_installed(pkgs) if (inherits(map, "mapview")) map = mapview2leaflet(map) m = initMap(map, map.types, sp::proj4string(x), viewer.suppress = viewer.suppress) @@ -334,8 +324,7 @@ leafletPixelsDF = function(x, ...) { pkgs = c("leaflet", "sp", "magrittr") - tst = sapply(pkgs, "requireNamespace", - quietly = TRUE, USE.NAMES = FALSE) + rlang::check_installed(pkgs) if (inherits(map, "mapview")) map = mapview2leaflet(map) if(!is.null(zcol)) x = x[, zcol] @@ -388,8 +377,7 @@ leafletPixelsDF = function(x, leafletSatellite = function(x, ...) { pkgs = c("leaflet", "satellite", "magrittr") - tst = sapply(pkgs, "requireNamespace", - quietly = TRUE, USE.NAMES = FALSE) + rlang::check_installed(pkgs) m = mapView(stack(x), ...) diff --git a/R/watch.R b/R/watch.R index 356eb8ce..49e2e30b 100644 --- a/R/watch.R +++ b/R/watch.R @@ -56,13 +56,7 @@ #' @export #' @rdname mapviewWatcher mapviewWatcher = function(env = .GlobalEnv, ...) { - - if (!requireNamespace("later", quietly = TRUE)) { - stop( - "Please install.packages('later') to allow mapview to watch your workspace" - , call. = FALSE - ) - } + rlang::check_installed("later") last_value = NULL From ccd9b212b1283f86ab733e66662c140611e47454 Mon Sep 17 00:00:00 2001 From: Brayden Nilson <45985474+B-Nilson@users.noreply.github.com> Date: Mon, 8 Dec 2025 22:33:13 +0000 Subject: [PATCH 2/2] include rlang as a depends --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 9db5df7c..08448ef8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -72,6 +72,7 @@ Imports: leafpop, png, raster (>= 3.6.3), + rlang, satellite, scales (>= 0.2.5), servr,