diff --git a/R/theme_ps.R b/R/theme_ps.R index 1eddafa7..fef8268c 100644 --- a/R/theme_ps.R +++ b/R/theme_ps.R @@ -8,39 +8,40 @@ #' @param plot.axes should the axes be shown? #' @param plot.legend should the legend(s) be shown? #' @export -theme_ps <- function(base_size = 12, base_family = "", plot.axes=FALSE, plot.legend=FALSE) { - if (!requireNamespace("ggplot2", quietly = TRUE)) { - stop("ggplot2 package needed for this function to work. Please install it.", - call. = FALSE) - } else { - replace <- function(e1, e2) { - e1[names(e2)] <- e2 - e1 - } - - tps <- replace(ggplot2::theme_minimal(base_size = base_size, base_family = base_family), - ggplot2::theme(panel.background = ggplot2::element_blank(), - panel.border = ggplot2::element_blank(), - panel.grid = ggplot2::element_blank(), - strip.background = ggplot2::element_blank(), - plot.background = ggplot2::element_blank(), - plot.title = ggplot2::element_blank(), - strip.text = ggplot2::element_blank(), - panel.spacing = unit(0,"null"), - plot.margin = rep(unit(0,"null"),4))) - - if (!plot.legend) { - tps <- replace(tps, ggplot2::theme(legend.position = "none")) - } - - if (plot.axes) { - tps - } else { - replace(tps, - ggplot2::theme(axis.text = ggplot2::element_blank(), - axis.title = ggplot2::element_blank(), - axis.ticks = ggplot2::element_line(), - axis.ticks.length = unit(0, "lines"))) - } - } +theme_ps <- function(base_size = 12, base_family = "", plot.axes = FALSE, plot.legend = FALSE) { + rlang::check_installed("ggplot2", reason = "to create plot themes.") + replace <- function(e1, e2) { + e1[names(e2)] <- e2 + e1 + } + tps <- replace( + ggplot2::theme_minimal(base_size = base_size, base_family = base_family), + ggplot2::theme( + panel.background = ggplot2::element_blank(), + panel.border = ggplot2::element_blank(), + panel.grid = ggplot2::element_blank(), + strip.background = ggplot2::element_blank(), + plot.background = ggplot2::element_blank(), + plot.title = ggplot2::element_blank(), + strip.text = ggplot2::element_blank(), + panel.spacing = unit(0, "null"), + plot.margin = rep(unit(0, "null"), 4) + ) + ) + if (!plot.legend) { + tps <- replace(tps, ggplot2::theme(legend.position = "none")) + } + if (plot.axes) { + tps + } else { + replace( + tps, + ggplot2::theme( + axis.text = ggplot2::element_blank(), + axis.title = ggplot2::element_blank(), + axis.ticks = ggplot2::element_line(), + axis.ticks.length = unit(0, "lines") + ) + ) + } } diff --git a/R/tmapGridAux.R b/R/tmapGridAux.R index c5a40a05..735ec24b 100644 --- a/R/tmapGridAux.R +++ b/R/tmapGridAux.R @@ -11,8 +11,7 @@ findZoom = function(b) { tmapGridTilesPrep = function(a, bs, id, o) { g = get("g", envir = .TMAP_GRID) - - if (!requireNamespace("maptiles")) stop("maptiles package is required", call. = FALSE) + rlang::check_installed("maptiles") crs = sf::st_crs(bs[[1]]) diff --git a/R/tmapGridInit.R b/R/tmapGridInit.R index bef31911..2b662133 100644 --- a/R/tmapGridInit.R +++ b/R/tmapGridInit.R @@ -1,6 +1,5 @@ tmapGridInit = function(o, return.asp = FALSE, vp) { - if (!requireNamespace("grid")) stop("grid package required but not installed yet.") - + rlang::check_installed("grid") rows = with(o, { x = c(outer.margins.top = outer.margins[3], diff --git a/R/tmapLeafletInit.R b/R/tmapLeafletInit.R index 9d9e6d60..d8466c51 100644 --- a/R/tmapLeafletInit.R +++ b/R/tmapLeafletInit.R @@ -33,7 +33,6 @@ addOverlayGroup <- function(group, are.tiles = FALSE) { tmapLeafletInit = function(o, return.asp = FALSE, vp) { if (return.asp) return(1) - if (!requireNamespace("leaflet")) stop("leaflet package required but not installed yet.") per_page = rep(o$ncols * o$nrows, o$npages) k = o$ncols * o$nrows * o$npages diff --git a/R/tmapShape.R b/R/tmapShape.R index bdc1edd7..bfe52f88 100644 --- a/R/tmapShape.R +++ b/R/tmapShape.R @@ -94,7 +94,7 @@ tmapShape.Raster = function(shp, is.main, crs, bbox, unit, filter, shp_name, sme #' @export tmapShape.SpatRaster = function(shp, is.main, crs, bbox, unit, filter, shp_name, smeta, o, tmf) { #tmapShape.stars(stars::st_as_stars(shp), is.main, crs, bbox, unit, filter, shp_name) - if (!requireNamespace("terra")) stop("terra package needed", call. = FALSE) + rlang::check_installed("terra") #if (!inherits(bbox, "bbox")) bbox = sf::st_bbox(bbox) diff --git a/R/tmapTrans.R b/R/tmapTrans.R index f0c7fd08..e2559d5e 100644 --- a/R/tmapTrans.R +++ b/R/tmapTrans.R @@ -189,7 +189,7 @@ tmapTransCartogram = function(shpTM, area, ord__, plot.order, args) { x = sf::st_sf(geometry = s, weight = area, tmapID__ = shpTM$tmapID) - if (!requireNamespace("cartogram")) stop("cartogram pacakge needed", call. = FALSE) + rlang::check_installed("cartogram") if (args$type == "cont") { shp = suppressMessages(suppressWarnings({cartogram::cartogram_cont(x, weight = "weight", itermax = args$itermax)})) diff --git a/R/tmap_animation.R b/R/tmap_animation.R index 191d522e..5034acac 100644 --- a/R/tmap_animation.R +++ b/R/tmap_animation.R @@ -57,9 +57,9 @@ tmap_animation <- function(tm, filename = NULL, width = NA, height = NA, dpi = N # check system requirements if (gif) { - if (!requireNamespace("gifski", quietly = TRUE)) stop("Package gifski is required for gif animations but not installed.") + rlang::check_installed("gifski", reason = "for creating gif animations.") } else { - if (!requireNamespace("av", quietly = TRUE)) stop("Package av is required for ffmpeg animations but not installed.") + rlang::check_installed("av", reason = "for ffmpeg animations") } if (is.na(dpi)) dpi <- .tmapOptions$output.dpi.animation diff --git a/R/tmap_icons.R b/R/tmap_icons.R index d00d4267..77fad3a2 100644 --- a/R/tmap_icons.R +++ b/R/tmap_icons.R @@ -86,32 +86,28 @@ marker_icon <- function() { # fix.borders is needed to prevent that right-hand side and bottom edges disappear pngGrob <- function(file, fix.borders=FALSE, n=NULL, height.inch=NULL, target.dpi=NULL) { - if (!requireNamespace("png", quietly = TRUE)) { - stop("png package needed for this function to work. Please install it.", - call. = FALSE) - } else { - pu <- is_path_or_url(file) - if (is.na(pu)) { - stop(file, " is neither a valid path nor url", call.=FALSE) - } + rlang::check_installed("png", reason = "for this function to work.") + pu <- is_path_or_url(file) + if (is.na(pu)) { + stop(file, " is neither a valid path nor url", call.=FALSE) + } - if (!pu) { - tmpfile <- tempfile(fileext=".png") - download.file(file, destfile=tmpfile, mode="wb") - file <- tmpfile - } + if (!pu) { + tmpfile <- tempfile(fileext=".png") + download.file(file, destfile=tmpfile, mode="wb") + file <- tmpfile + } - x <- png::readPNG(file) + x <- png::readPNG(file) - if (fix.borders) { - if (dim(x)[3]==3) { - x <- array(c(x, rep(1, dim(x)[1]*dim(x)[2])), dim = c(dim(x)[1], dim(x)[2], dim(x)[3]+1)) - } - x2 <- add_zero_borders_to_3d_array(x, n=n, height.inch=height.inch,target.dpi=target.dpi) - rasterGrob(x2, interpolate=TRUE) - } else { - rasterGrob(x, interpolate=TRUE) + if (fix.borders) { + if (dim(x)[3]==3) { + x <- array(c(x, rep(1, dim(x)[1]*dim(x)[2])), dim = c(dim(x)[1], dim(x)[2], dim(x)[3]+1)) } + x2 <- add_zero_borders_to_3d_array(x, n=n, height.inch=height.inch,target.dpi=target.dpi) + rasterGrob(x2, interpolate=TRUE) + } else { + rasterGrob(x, interpolate=TRUE) } } diff --git a/_pkgdown.yml b/_pkgdown.yml index 5f8581c0..35028441 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -3,6 +3,3 @@ template: bootstrap: 5 bslib: primary: "#5f8640" - -development: - mode: auto