Skip to content

Commit

Permalink
fix: Quieter 'convert_polygon_sf_to_polygon_df()'
Browse files Browse the repository at this point in the history
* An internal function `convert_polygon_sf_to_polygon_df()` will now be a bit more
  quiet (throw WARNINGs less often).
  • Loading branch information
trevorld committed Nov 7, 2022
1 parent 4675e10 commit 8cd19de
Show file tree
Hide file tree
Showing 70 changed files with 2,405 additions and 2,388 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: gridpattern
Type: Package
Title: 'grid' Pattern Grobs
Version: 1.0.1
Version: 1.0.2
Authors@R: c(person("Mike", "FC", role = "aut", comment = "Code/docs adapted from ggpattern"),
person("Trevor L", "Davis", role=c("aut", "cre"), email="[email protected]",
comment = c(ORCID = "0000-0001-6341-4639")),
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
gridpattern v1.0.2
==================

Bug fixes and minor improvements
--------------------------------

* An internal function `convert_polygon_sf_to_polygon_df()` will now be a bit more
quiet (throw WARNINGs less often).

gridpattern v1.0.1
==================

Expand Down
1 change: 0 additions & 1 deletion R/gridpattern-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@
#' }
#' Note to use the R v4.1.0 features one needs R be (at least) version 4.1 and not all graphic devices
#' support any/all these features. See \url{https://www.stat.auckland.ac.nz/~paul/Reports/GraphicsEngine/definitions/definitions.html} for more information on these features.
#' @keywords internal
"_PACKAGE"
26 changes: 16 additions & 10 deletions R/utils-polygon_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ convert_polygon_df_to_polygon_sf <- function(polygon_df, buffer_dist = 0) {
res
}

#' Convert a sf POLYGON/MULTIPOLYGON into a polygon_df
#' Convert a sf GEOMETRYCOLLECTION/POLYGON/MULTIPOLYGON into a polygon_df
#'
#' @param mp sf POLYGON or MULTIPOLYGON object
#' @param mp sf GEOMETRYCOLLECTION, POLYGON, or MULTIPOLYGON object
#'
#' @return polygon_df data.frame object
#'
Expand All @@ -104,8 +104,13 @@ convert_polygon_sf_to_polygon_df <- function(mp) {
mat <- as.matrix(mp)
if (sf::st_is_empty(mp))
return(mat)
if (!inherits(mp, 'POLYGON') && !inherits(mp, 'MULTIPOLYGON') && !inherits(mp, 'GEOMETRYCOLLECTION')) {
warn(paste0("convert_polygon_sf_to_polygon_df(): Not POLYGON or MULTIPOLYGON: ", deparse(class(mp))))
if (!inherits(mp, c('POLYGON', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION',
'MULTILINESTRING', 'MULTIPOINT', 'LINESTRING', 'POINT'))) {
warn(paste("convert_polygon_sf_to_polygon_df():",
"Not GEOMETRYCOLLECTION, POLYGON, or MULTIPOLYGON:",
deparse(class(mp))))
}
if (!inherits(mp, c('POLYGON', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION'))) {
return(NULL)
}

Expand All @@ -116,17 +121,18 @@ convert_polygon_sf_to_polygon_df <- function(mp) {
}

get_poly_lengths <- function(sf_object) {
if (inherits(sf_object, 'POLYGON') || inherits(sf_object, 'LINESTRING') || inherits(sf_object, 'POINT')) {
if (inherits(sf_object, c('POLYGON', 'LINESTRING', 'POINT'))) {
nrow(as.matrix(sf_object))
} else if (inherits(sf_object, 'MULTIPOLYGON')) {
} else if (inherits(sf_object, c('MULTIPOLYGON', 'MULTILINESTRING', 'MULTIPOINT'))) {
if (max(lengths(sf_object)) > 1L)
abort("There is a MULTIPOLYGON with length greater than 1")
vapply(sf_object, function(x) {nrow(x[[1]])}, integer(1))
abort("There is a MULTIPOLYGON/MULTILINESTRING/MULTIPOINT with length greater than 1")
vapply(sf_object, function(x) nrow(as.matrix(x[[1]])), integer(1))
} else if (inherits(sf_object, 'GEOMETRYCOLLECTION')) {
vapply(sf_object, get_poly_lengths, integer(1))
} else {
abort(paste0("convert_polygon_sf_to_polygon_df(): Not POLYGON or MULTIPOLYGON: ",
deparse(class(sf_object))))
abort(paste("convert_polygon_sf_to_polygon_df():",
"Not GEOMETRYCOLLECTION, POLYGON, or MULTIPOLYGON:",
deparse(class(sf_object))))
}
}

Expand Down
Binary file modified man/figures/README-circle-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-ggpattern-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-hex_ggpattern-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-piecepackr-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-rhombitrihexagonal-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-rose-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-text-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-truncated_hexagonal-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-wave-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-weave-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion man/gridpattern-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified tests/figs/array/placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 34 additions & 34 deletions tests/testthat/_snaps/geometry/circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 44 additions & 44 deletions tests/testthat/_snaps/geometry/crosshatch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8cd19de

Please sign in to comment.