From cf6e74b14f8aa0a9a4eb83a9e9630363e005dcf9 Mon Sep 17 00:00:00 2001 From: Rob Williams Date: Wed, 17 Feb 2021 17:43:51 -0500 Subject: [PATCH] make requested CRAN changes --- CRAN-RELEASE | 4 ++-- R/dms2dd.R | 2 +- R/overlap.weight.R | 2 +- R/point.poly.dist.R | 10 ++++----- R/theme_rw.R | 1 + cran-comments.md | 4 ++++ man/overlap.weight.Rd | 2 +- man/point.poly.dist.Rd | 2 +- man/theme_rw.Rd | 3 +++ tests/testthat/test-dms2dd.R | 4 ++-- tests/testthat/test-overlap.weight.R | 4 ++-- tests/testthat/test-pointpolydist.R | 2 +- vignettes/spatial-utility-functions.Rmd | 28 ++++++++++++++++--------- 13 files changed, 42 insertions(+), 26 deletions(-) diff --git a/CRAN-RELEASE b/CRAN-RELEASE index ecef1c1..5d72f24 100644 --- a/CRAN-RELEASE +++ b/CRAN-RELEASE @@ -1,2 +1,2 @@ -This package was submitted to CRAN on 2021-01-14. -Once it is accepted, delete this file and tag the release (commit 45bc3fc). +This package was submitted to CRAN on 2021-02-17. +Once it is accepted, delete this file and tag the release (commit c63247d). diff --git a/R/dms2dd.R b/R/dms2dd.R index 1abeafb..a3547cc 100644 --- a/R/dms2dd.R +++ b/R/dms2dd.R @@ -41,7 +41,7 @@ dms2dd <- function(lon, lat) { coords <- strsplit(c(lon[i], lat[i]), '\\s') - card_dir <- vapply(coords, function(x) length(x) == 4, FUN.VALUE = T) + card_dir <- vapply(coords, function(x) length(x) == 4, FUN.VALUE = TRUE) if (all(card_dir)) { diff --git a/R/overlap.weight.R b/R/overlap.weight.R index 72a272a..c41058d 100644 --- a/R/overlap.weight.R +++ b/R/overlap.weight.R @@ -45,7 +45,7 @@ #' crs = CRS(st_crs(polys_t)$proj4string)) #' overlap.weight(raster_t, polys_t) -overlap.weight <- function(raster, polygons, count = F, warn = T) { +overlap.weight <- function(raster, polygons, count = FALSE, warn = TRUE) { polygons <- poly.conv(polygons, raster) diff --git a/R/point.poly.dist.R b/R/point.poly.dist.R index a57dc0a..c59624e 100644 --- a/R/point.poly.dist.R +++ b/R/point.poly.dist.R @@ -24,7 +24,7 @@ #' crs = 4326) #' point.poly.dist(points, polys) -point.poly.dist <- function(point, poly, max = T, by_element = F) { +point.poly.dist <- function(point, poly, max = TRUE, by_element = FALSE) { ## convert to sfc if necessary if (inherits(poly, 'Spatial')) poly <- st_as_sfc(poly) @@ -40,10 +40,10 @@ point.poly.dist <- function(point, poly, max = T, by_element = F) { ## calculate distance from point to every border vertex if (st_is_longlat(poly)) { - if (!'geosphere' %in% rownames(utils::installed.packages())) { - stop(paste0('Package geosphere required to calculate distances for ', - 'unprojected data\n', - 'Install with install.packages("geosphere")\n')) + if (!requireNamespace("geosphere")) { + stop(paste0("Package geosphere required to calculate distances for ", + "unprojected data\n", + "Install with: install.packages(\"geosphere\")\n")) } dists <- do.call(rbind, diff --git a/R/theme_rw.R b/R/theme_rw.R index 9692957..5b5f9d8 100644 --- a/R/theme_rw.R +++ b/R/theme_rw.R @@ -2,6 +2,7 @@ #' #' A ggplot theme with no grid elements or gray background. #' +#' @return A ggplot [theme][ggplot2::theme] object. #' @export #' #' @examples diff --git a/cran-comments.md b/cran-comments.md index 9e64b99..059c538 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -4,6 +4,10 @@ This is a resubmission. In this version I have: * Fixed the Date field in DESCRIPTION from 2020-01-14 to 2021-02-17 * I forgot to confirm the initial resubmission on 2021-01-14, so I am resubmitting again +* Used TRUE and FALSE throughout +* Added a \value to theme_rw.Rd +* Used requireNamespace instead of installed.packages() +* Reset user's par() in vignette spatial-utility-function.Rmd ## Test environments diff --git a/man/overlap.weight.Rd b/man/overlap.weight.Rd index 8b850f5..929b43c 100644 --- a/man/overlap.weight.Rd +++ b/man/overlap.weight.Rd @@ -4,7 +4,7 @@ \alias{overlap.weight} \title{Weight Raster Cells by Overlapping Polygons} \usage{ -overlap.weight(raster, polygons, count = F, warn = T) +overlap.weight(raster, polygons, count = FALSE, warn = TRUE) } \arguments{ \item{raster}{a RasterLayer object.} diff --git a/man/point.poly.dist.Rd b/man/point.poly.dist.Rd index e703466..1f1393c 100644 --- a/man/point.poly.dist.Rd +++ b/man/point.poly.dist.Rd @@ -4,7 +4,7 @@ \alias{point.poly.dist} \title{Point-Polygon Distances} \usage{ -point.poly.dist(point, poly, max = T, by_element = F) +point.poly.dist(point, poly, max = TRUE, by_element = FALSE) } \arguments{ \item{point}{A simplefeatures object of class point.} diff --git a/man/theme_rw.Rd b/man/theme_rw.Rd index 1673bd4..bfef039 100644 --- a/man/theme_rw.Rd +++ b/man/theme_rw.Rd @@ -6,6 +6,9 @@ \usage{ theme_rw() } +\value{ +A ggplot \link[ggplot2:theme]{theme} object. +} \description{ A ggplot theme with no grid elements or gray background. } diff --git a/tests/testthat/test-dms2dd.R b/tests/testthat/test-dms2dd.R index 6ea747d..97d0a08 100644 --- a/tests/testthat/test-dms2dd.R +++ b/tests/testthat/test-dms2dd.R @@ -3,13 +3,13 @@ test_that("dms2dd works with heterogeneous input", { "71° 3' 32\" W"), lat = c("47° 36' 22\"", "42° 21' 36\" N"), - stringsAsFactors = F) + stringsAsFactors = FALSE) expect_equal(dms2dd(ll[, 'lon'], ll[, 'lat'])[1,2], 47.60611, tolerance = 1e-3) }) test_that("dms2dd works with 0 values", { ll <- data.frame(lon = c("71° 0' 32\" W"), lat = c("0° 21' 36\" N"), - stringsAsFactors = F) + stringsAsFactors = FALSE) expect_equal(dms2dd(ll[, 'lon'], ll[, 'lat'])[1,1], -71.00889, tolerance = 1e-3) }) diff --git a/tests/testthat/test-overlap.weight.R b/tests/testthat/test-overlap.weight.R index d549ae3..c8502e8 100644 --- a/tests/testthat/test-overlap.weight.R +++ b/tests/testthat/test-overlap.weight.R @@ -28,9 +28,9 @@ test_that("overlap.weight works with SpatialPolygonsDataFrame", { }) test_that("overlap.weight works with count", { - expect_equal(overlap.weight(raster_t, polys_t, count = T)[4,4], 2) + expect_equal(overlap.weight(raster_t, polys_t, count = TRUE)[4,4], 2) }) test_that("overlap.weight works silently", { - expect_silent(overlap.weight(raster_t, polys_t, warn = F)) + expect_silent(overlap.weight(raster_t, polys_t, warn = FALSE)) }) diff --git a/tests/testthat/test-pointpolydist.R b/tests/testthat/test-pointpolydist.R index 04b8b22..0c758c7 100644 --- a/tests/testthat/test-pointpolydist.R +++ b/tests/testthat/test-pointpolydist.R @@ -10,7 +10,7 @@ test_that("point.poly.dist works with arguments", { expect_equal(point.poly.dist(points_t, poly_t, max = FALSE), 61895.43, tolerance = 1e-3) expect_equal(point.poly.dist(points_t, poly_t, max = FALSE, - by_element = T)[2], 61895.43, + by_element = TRUE)[2], 61895.43, tolerance = 1e-3) }) diff --git a/vignettes/spatial-utility-functions.Rmd b/vignettes/spatial-utility-functions.Rmd index 08bcc7d..3fcfac6 100644 --- a/vignettes/spatial-utility-functions.Rmd +++ b/vignettes/spatial-utility-functions.Rmd @@ -17,13 +17,16 @@ knitr::opts_chunk$set( fig.height = 3, fig.align = 'center' ) + +## old graphical parameters +oldpar <- par(mfrow = c(1,2)) ``` This package contains convenience functions for carrying out GIS operations that I have repeatedly encountered in my research. The following packages are used in this vignette: -```{r setup, message = F, warning = F, results = 'hide'} +```{r setup, message = FALSE, warning = FALSE, results = 'hide'} library(sf) library(raster) library(RWmisc) @@ -58,15 +61,15 @@ par(mfrow = c(1, 3)) ## plot raw raster values plot(raster_t, main = 'raw') -plot(polys_t, add = T) +plot(polys_t, add = TRUE) ## plot count of overlapping polygons -plot(overlap.weight(raster_t, polys_t, count = T), main = "count") -plot(polys_t, add = T) +plot(overlap.weight(raster_t, polys_t, count = TRUE), main = "count") +plot(polys_t, add = TRUE) ## plot overlap-weighted raster values plot(overlap.weight(raster_t, polys_t), main = "weighted") -plot(polys_t, add = T) +plot(polys_t, add = TRUE) ``` # Projecting spatial objects to UTM @@ -109,7 +112,7 @@ geographic and projected data. nc_centroids <- st_centroid(nc) ## calculate maximum distance -point.poly.dist(nc_centroids[53,]$geometry, nc[53,]$geometry, max = T) +point.poly.dist(nc_centroids[53,]$geometry, nc[53,]$geometry, max = TRUE) ``` The following illustration depicts the line connecting the centroid of the @@ -137,9 +140,9 @@ nearest_point <- rbind(st_coordinates(nc_points[nearest_ind,]), ## plot par(mar = rep(0,4)) plot(nc[53,]$geometry) -plot(nc_centroids[53,]$geometry, add = T) -plot(farthest_point, add = T, col = 'red') -plot(nearest_point, add = T, col = 'blue') +plot(nc_centroids[53,]$geometry, add = TRUE) +plot(farthest_point, add = TRUE, col = 'red') +plot(nearest_point, add = TRUE, col = 'blue') ``` Carrying out the same calculations using built-in `sf` functions takes roughly @@ -147,9 +150,14 @@ twice as long to execute. ```{r point-poly-dist-benchmark} microbenchmark::microbenchmark(pk = point.poly.dist(nc_centroids[53,]$geometry, - nc[53,]$geometry, max = T), + nc[53,]$geometry, max = TRUE), sf = st_distance(st_cast(st_geometry(nc[53,]), 'POINT')[farthest_ind], nc_centroids[53,]), times = 100) ``` + +```{r oldpar, echo = FALSE} +par(oldpar) +``` +