From fdc5093a1449e8b6017f4d4ad77e223d77f0a63d Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Thu, 8 Jun 2023 17:35:25 -0400 Subject: [PATCH] Move sp set_evolution_status function and update documentation --- DESCRIPTION | 2 +- R/plot-map.R | 13 ++++++++----- R/transform.R | 19 +++++++++++++++++++ R/usmap.R | 7 ------- man/set_sp_evolution_status.Rd | 17 +++++++++++++++++ man/theme_map.Rd | 15 ++++++++------- 6 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 man/set_sp_evolution_status.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 3d4142b..057bbd4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,6 +29,6 @@ Suggests: sf, stringr, testthat -RoxygenNote: 7.2.2 +RoxygenNote: 7.2.3 Roxygen: list(markdown = TRUE) VignetteBuilder: knitr diff --git a/R/plot-map.R b/R/plot-map.R index cd3594e..69f59ed 100644 --- a/R/plot-map.R +++ b/R/plot-map.R @@ -149,15 +149,18 @@ plot_usmap <- function(regions = c("states", "state", "counties", "county"), ggplot2::ggplot(data = map_df) + polygon_layer + label_layer + ggplot2::coord_equal() + theme } -#' This creates a nice map theme for use in plot_usmap. -#' It is borrowed from the ggthemes package located at this repository: -#' https://github.com/jrnold/ggthemes +#' Convenient theme map +#' +#' @description +#' This creates a nice map theme for use in [plot_usmap]. +#' It is borrowed from the `ggthemes` package located at this repository: +#' \link{https://github.com/jrnold/ggthemes}. #' #' This function was manually rewritten here to avoid the need for #' another package import. #' -#' All theme functions (i.e. theme_bw, theme, element_blank, %+replace%) -#' come from ggplot2. +#' All theme functions (i.e. `theme_bw`, `theme`, `element_blank`, `%+replace%`) +#' come from [ggplot2]. #' #' @keywords internal theme_map <- function(base_size = 9, base_family = "") { diff --git a/R/transform.R b/R/transform.R index 4387771..59e23d4 100644 --- a/R/transform.R +++ b/R/transform.R @@ -48,6 +48,7 @@ usmap_transform <- function(data, output_names = c("x", "y")) { # check for sf + set_sp_evolution_status() if (!requireNamespace("sf", quietly = TRUE)) { stop("`sf` must be installed to use `usmap_transform`. Use: install.packages(\"sf\") and try again.") @@ -199,6 +200,8 @@ usmap_transform.data.frame <- function(data, #' #' @export usmap_crs <- function() { + set_sp_evolution_status() + if (!requireNamespace("sf", quietly = TRUE)) { stop("`sf` must be installed to use `usmap_transform`. Use: install.packages(\"sf\") and try again.") @@ -212,3 +215,19 @@ usmap_crs <- function() { sp::CRS(paste("+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0", "+a=6370997 +b=6370997 +units=m +no_defs")) } + +#' Set sp evolution status +#' +#' @description +#' Sets the `sp` evolution status to "2" to +#' force usage of `sf` instead of `rgdal` +#' which is being retired. +#' +#' This can be removed in the future when the evolution status +#' is set to >= 2 by default in `sf`. +#' +#' @keywords internal +set_sp_evolution_status <- function() { + if (sp::get_evolution_status() < 2L) + sp::set_evolution_status(2L) +} diff --git a/R/usmap.R b/R/usmap.R index 52cec26..23b44a1 100644 --- a/R/usmap.R +++ b/R/usmap.R @@ -70,13 +70,6 @@ if (getRversion() >= "2.15.1") utils::globalVariables(c("abbr", "county", "group", "x", "y")) -.onLoad <- function(libname, pkgname) { - ## Ensure latest evolution status of sp is used. - ## Replaces rgdal usage with sf package. - if (sp::get_evolution_status() != 2L) - sp::set_evolution_status(2L) -} - #' Retrieve US map data #' #' @param regions The region breakdown for the map, can be one of diff --git a/man/set_sp_evolution_status.Rd b/man/set_sp_evolution_status.Rd new file mode 100644 index 0000000..30a8f1d --- /dev/null +++ b/man/set_sp_evolution_status.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/transform.R +\name{set_sp_evolution_status} +\alias{set_sp_evolution_status} +\title{Set sp evolution status} +\usage{ +set_sp_evolution_status() +} +\description{ +Sets the \code{sp} evolution status to "2" to +force usage of \code{sf} instead of \code{rgdal} +which is being retired. + +This can be removed in the future when the evolution status +is set to >= 2 by default in \code{sf}. +} +\keyword{internal} diff --git a/man/theme_map.Rd b/man/theme_map.Rd index fe89c06..ede0994 100644 --- a/man/theme_map.Rd +++ b/man/theme_map.Rd @@ -2,18 +2,19 @@ % Please edit documentation in R/plot-map.R \name{theme_map} \alias{theme_map} -\title{This creates a nice map theme for use in plot_usmap. -It is borrowed from the ggthemes package located at this repository: -https://github.com/jrnold/ggthemes} +\title{Convenient theme map} \usage{ theme_map(base_size = 9, base_family = "") } \description{ +This creates a nice map theme for use in \link{plot_usmap}. +It is borrowed from the \code{ggthemes} package located at this repository: +\link{https://github.com/jrnold/ggthemes}. + This function was manually rewritten here to avoid the need for another package import. -} -\details{ -All theme functions (i.e. theme_bw, theme, element_blank, \%+replace\%) -come from ggplot2. + +All theme functions (i.e. \code{theme_bw}, \code{theme}, \code{element_blank}, \verb{\%+replace\%}) +come from \link{ggplot2}. } \keyword{internal}