From 6abc877942e31e476fa072244a4b6f2ccfa44bf7 Mon Sep 17 00:00:00 2001 From: Luuk van der Meer Date: Wed, 22 Mar 2023 14:51:14 +0100 Subject: [PATCH 1/6] refactor: Make sf S3 methods consistent --- R/sf.R | 49 ++++++++++++++++++++++++------------------------ man/as.linnet.Rd | 2 +- man/sf.Rd | 17 +++++++++++------ 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/R/sf.R b/R/sf.R index 1f36fd16..16caac49 100644 --- a/R/sf.R +++ b/R/sf.R @@ -16,6 +16,8 @@ is.sfg = function(x) { #' #' @param x An object of class \code{\link{sfnetwork}}. #' +#' @param obj An object of class \code{\link{sfnetwork}}. +#' #' @param y An object of class \code{\link[sf]{sf}}, or directly convertible to #' it using \code{\link[sf]{st_as_sf}}. In some cases, it can also be an object #' of \code{\link[sf:st]{sfg}} or \code{\link[sf:st_bbox]{bbox}}. Always look @@ -30,6 +32,9 @@ is.sfg = function(x) { #' @param value The value to be assigned. See the documentation of the #' corresponding sf function for details. #' +#' @param precision The precision to be assigned. See +#' \code{\link[sf]{st_precision}} for details. +#' #' @return The \code{sfnetwork} method for \code{\link[sf]{st_as_sf}} returns #' the active element of the network as object of class \code{\link[sf]{sf}}. #' The \code{sfnetwork} and \code{morphed_sfnetwork} methods for @@ -118,8 +123,8 @@ st_as_s2.sfnetwork = function(x, active = NULL, ...) { #' #' @importFrom sf st_geometry #' @export -st_geometry.sfnetwork = function(x, active = NULL, ...) { - pull_geom(x, active) +st_geometry.sfnetwork = function(obj, active = NULL, ...) { + pull_geom(obj, active) } #' @name sf @@ -149,12 +154,12 @@ st_drop_geometry.sfnetwork = function(x, ...) { #' #' @importFrom sf st_bbox st_geometry #' @export -st_bbox.sfnetwork = function(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") +st_bbox.sfnetwork = function(obj, active = NULL, ...) { + if (is.null(active)) active = attr(obj, "active") switch( active, - nodes = st_bbox(pull_node_geom(x), ...), - edges = st_bbox(pull_edge_geom(x), ...), + nodes = st_bbox(pull_node_geom(obj), ...), + edges = st_bbox(pull_edge_geom(obj), ...), raise_unknown_input(active) ) } @@ -226,27 +231,21 @@ st_crs.sfnetwork = function(x, active = NULL, ...) { #' @name sf #' @importFrom sf st_precision #' @export -st_precision.sfnetwork = function(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") - switch( - active, - nodes = st_precision(pull_node_geom(x), ...), - edges = st_precision(pull_edge_geom(x), ...), - raise_unknown_input(active) - ) +st_precision.sfnetwork = function(x) { + st_precision(pull_geom(x)) } #' @name sf #' @importFrom sf st_set_precision st_precision<- #' @export -st_set_precision.sfnetwork = function(x, value) { +st_set_precision.sfnetwork = function(x, precision) { if (attr(x, "active") == "edges" || has_explicit_edges(x)) { geom = pull_edge_geom(x) - st_precision(geom) = value + st_precision(geom) = precision x = mutate_edge_geom(x, geom) } geom = pull_node_geom(x) - st_precision(geom) = value + st_precision(geom) = precision mutate_node_geom(x, geom) } @@ -288,12 +287,12 @@ st_zm.sfnetwork = function(x, ...) { #' @name sf #' @importFrom sf st_geometry st_m_range #' @export -st_m_range.sfnetwork = function(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") +st_m_range.sfnetwork = function(obj, active = NULL, ...) { + if (is.null(active)) active = attr(obj, "active") switch( active, - nodes = st_m_range(pull_node_geom(x), ...), - edges = st_m_range(pull_edge_geom(x), ...), + nodes = st_m_range(pull_node_geom(obj), ...), + edges = st_m_range(pull_edge_geom(obj), ...), raise_unknown_input(active) ) } @@ -301,12 +300,12 @@ st_m_range.sfnetwork = function(x, active = NULL, ...) { #' @name sf #' @importFrom sf st_geometry st_z_range #' @export -st_z_range.sfnetwork = function(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") +st_z_range.sfnetwork = function(obj, active = NULL, ...) { + if (is.null(active)) active = attr(obj, "active") switch( active, - nodes = st_z_range(pull_node_geom(x), ...), - edges = st_z_range(pull_edge_geom(x), ...), + nodes = st_z_range(pull_node_geom(obj), ...), + edges = st_z_range(pull_edge_geom(obj), ...), raise_unknown_input(active) ) } diff --git a/man/as.linnet.Rd b/man/as.linnet.Rd index a4c61239..ac814f8b 100644 --- a/man/as.linnet.Rd +++ b/man/as.linnet.Rd @@ -5,7 +5,7 @@ \alias{as.linnet.sfnetwork} \title{Convert a sfnetwork into a linnet} \usage{ -as.linnet.sfnetwork(X, ...) +\method{as.linnet}{sfnetwork}(X, ...) } \arguments{ \item{X}{An object of class \code{\link{sfnetwork}} with a projected CRS.} diff --git a/man/sf.Rd b/man/sf.Rd index 8f70a2f8..9b6698ba 100644 --- a/man/sf.Rd +++ b/man/sf.Rd @@ -46,13 +46,13 @@ \method{st_as_s2}{sfnetwork}(x, active = NULL, ...) -\method{st_geometry}{sfnetwork}(x, active = NULL, ...) +\method{st_geometry}{sfnetwork}(obj, active = NULL, ...) \method{st_geometry}{sfnetwork}(x) <- value \method{st_drop_geometry}{sfnetwork}(x, ...) -\method{st_bbox}{sfnetwork}(x, active = NULL, ...) +\method{st_bbox}{sfnetwork}(obj, active = NULL, ...) \method{st_coordinates}{sfnetwork}(x, active = NULL, ...) @@ -64,9 +64,9 @@ \method{st_crs}{sfnetwork}(x) <- value -\method{st_precision}{sfnetwork}(x, active = NULL, ...) +\method{st_precision}{sfnetwork}(x) -\method{st_set_precision}{sfnetwork}(x, value) +\method{st_set_precision}{sfnetwork}(x, precision) \method{st_shift_longitude}{sfnetwork}(x, ...) @@ -78,9 +78,9 @@ \method{st_zm}{sfnetwork}(x, ...) -\method{st_m_range}{sfnetwork}(x, active = NULL, ...) +\method{st_m_range}{sfnetwork}(obj, active = NULL, ...) -\method{st_z_range}{sfnetwork}(x, active = NULL, ...) +\method{st_z_range}{sfnetwork}(obj, active = NULL, ...) \method{st_agr}{sfnetwork}(x, active = NULL, ...) @@ -127,9 +127,14 @@ the given network. Defaults to \code{NULL}.} \item{...}{Arguments passed on the corresponding \code{sf} function.} +\item{obj}{An object of class \code{\link{sfnetwork}}.} + \item{value}{The value to be assigned. See the documentation of the corresponding sf function for details.} +\item{precision}{The precision to be assigned. See +\code{\link[sf]{st_precision}} for details.} + \item{y}{An object of class \code{\link[sf]{sf}}, or directly convertible to it using \code{\link[sf]{st_as_sf}}. In some cases, it can also be an object of \code{\link[sf:st]{sfg}} or \code{\link[sf:st_bbox]{bbox}}. Always look From d6870d19b62be5a7f56fe3e98d804d90996c71d7 Mon Sep 17 00:00:00 2001 From: Luuk van der Meer Date: Wed, 22 Mar 2023 14:56:40 +0100 Subject: [PATCH 2/6] refactor: Make st_crs consistent with st_precision :construction: --- R/sf.R | 10 ++-------- man/sf.Rd | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/R/sf.R b/R/sf.R index 16caac49..733888f7 100644 --- a/R/sf.R +++ b/R/sf.R @@ -204,14 +204,8 @@ st_is_valid.sfnetwork = function(x, ...) { #' #' @importFrom sf st_crs #' @export -st_crs.sfnetwork = function(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") - switch( - active, - nodes = st_crs(pull_node_geom(x), ...), - edges = st_crs(pull_edge_geom(x), ...), - raise_unknown_input(active) - ) +st_crs.sfnetwork = function(x, ...) { + st_crs(pull_geom(x), ...) } #' @name sf diff --git a/man/sf.Rd b/man/sf.Rd index 9b6698ba..dc060d87 100644 --- a/man/sf.Rd +++ b/man/sf.Rd @@ -60,7 +60,7 @@ \method{st_is_valid}{sfnetwork}(x, ...) -\method{st_crs}{sfnetwork}(x, active = NULL, ...) +\method{st_crs}{sfnetwork}(x, ...) \method{st_crs}{sfnetwork}(x) <- value From bf6651edc8dad3e390949af80a938f0794823e5c Mon Sep 17 00:00:00 2001 From: Luuk van der Meer Date: Wed, 22 Mar 2023 15:07:36 +0100 Subject: [PATCH 3/6] refactor: Tidy sf script :construction: --- R/sf.R | 76 +++++++++++++--------------------------------------------- 1 file changed, 17 insertions(+), 59 deletions(-) diff --git a/R/sf.R b/R/sf.R index 733888f7..a83b7192 100644 --- a/R/sf.R +++ b/R/sf.R @@ -100,13 +100,7 @@ edges_as_sf = function(x, ...) { #' @importFrom sf st_as_s2 #' @export st_as_s2.sfnetwork = function(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") - switch( - active, - nodes = st_as_s2(pull_node_geom(x), ...), - edges = st_as_s2(pull_edge_geom(x), ...), - raise_unknown_input(active) - ) + st_as_s2(pull_geom(x, active), ...) } # ============================================================================= @@ -152,45 +146,31 @@ st_drop_geometry.sfnetwork = function(x, ...) { #' # Get bbox of the active network element. #' st_bbox(net) #' -#' @importFrom sf st_bbox st_geometry +#' @importFrom sf st_bbox #' @export st_bbox.sfnetwork = function(obj, active = NULL, ...) { - if (is.null(active)) active = attr(obj, "active") - switch( - active, - nodes = st_bbox(pull_node_geom(obj), ...), - edges = st_bbox(pull_edge_geom(obj), ...), - raise_unknown_input(active) - ) + st_bbox(pull_geom(obj, active), ...) } #' @name sf -#' @importFrom sf st_coordinates st_geometry +#' @importFrom sf st_coordinates #' @export st_coordinates.sfnetwork = function(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") - switch( - active, - nodes = st_coordinates(pull_node_geom(x), ...), - edges = st_coordinates(pull_edge_geom(x), ...), - raise_unknown_input(active) - ) + st_coordinates(pull_geom(x, active), ...) } #' @name sf #' @importFrom sf st_is #' @export st_is.sfnetwork = function(x, ...) { - active = attr(x, "active") - st_is(pull_geom(x, active), ...) + st_is(pull_geom(x), ...) } #' @name sf #' @importFrom sf st_is_valid #' @export st_is_valid.sfnetwork = function(x, ...) { - active = attr(x, "active") - st_is_valid(pull_geom(x, active), ...) + st_is_valid(pull_geom(x), ...) } # ============================================================================= @@ -279,29 +259,17 @@ st_zm.sfnetwork = function(x, ...) { } #' @name sf -#' @importFrom sf st_geometry st_m_range +#' @importFrom sf st_m_range #' @export st_m_range.sfnetwork = function(obj, active = NULL, ...) { - if (is.null(active)) active = attr(obj, "active") - switch( - active, - nodes = st_m_range(pull_node_geom(obj), ...), - edges = st_m_range(pull_edge_geom(obj), ...), - raise_unknown_input(active) - ) + st_m_range(pull_geom(obj, active), ...) } #' @name sf -#' @importFrom sf st_geometry st_z_range +#' @importFrom sf st_z_range #' @export st_z_range.sfnetwork = function(obj, active = NULL, ...) { - if (is.null(active)) active = attr(obj, "active") - switch( - active, - nodes = st_z_range(pull_node_geom(obj), ...), - edges = st_z_range(pull_edge_geom(obj), ...), - raise_unknown_input(active) - ) + st_z_range(pull_geom(obj, active), ...) } change_coords = function(x, op, ...) { @@ -330,13 +298,7 @@ change_coords = function(x, op, ...) { #' @importFrom sf st_agr #' @export st_agr.sfnetwork = function(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") - switch( - active, - nodes = node_agr(x), - edges = edge_agr(x), - raise_unknown_input(active) - ) + agr(x, active) } #' @name sf @@ -772,11 +734,10 @@ find_indices_to_drop = function(x, y, ..., .operator = sf::st_filter) { #' @importFrom sf st_geometry st_intersects #' @export st_intersects.sfnetwork = function(x, y, ...) { - active = attr(x, "active") if (missing(y)) { - st_intersects(pull_geom(x, active), ...) + st_intersects(pull_geom(x), ...) } else { - st_intersects(pull_geom(x, active), st_geometry(y), ...) + st_intersects(pull_geom(x), st_geometry(y), ...) } } @@ -784,22 +745,19 @@ st_intersects.sfnetwork = function(x, y, ...) { #' @importFrom sf st_as_sf st_sample #' @export st_sample.sfnetwork = function(x, ...) { - active = attr(x, "active") - st_sample(st_as_sf(x, active), ...) + st_sample(st_as_sf(x), ...) } #' @name sf #' @importFrom sf st_geometry st_nearest_points #' @export st_nearest_points.sfnetwork = function(x, y, ...) { - active = attr(x, "active") - st_nearest_points(pull_geom(x, active), st_geometry(y), ...) + st_nearest_points(pull_geom(x), st_geometry(y), ...) } #' @name sf #' @importFrom sf st_area #' @export st_area.sfnetwork = function(x, ...) { - active = attr(x, "active") - st_area(pull_geom(x, active), ...) + st_area(pull_geom(x), ...) } From af490854744a3d4c396b451c4fe0a64d6f130c6f Mon Sep 17 00:00:00 2001 From: Luuk van der Meer Date: Wed, 22 Mar 2023 15:13:37 +0100 Subject: [PATCH 4/6] release: Version bump to 0.6.3 :bookmark: --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 001c6e77..1b561ce2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: sfnetworks Title: Tidy Geospatial Networks -Version: 0.6.2 +Version: 0.6.3 Authors@R: c(person(given = "Lucas", family = "van der Meer", From 839dcabcecfa7ff3e8ba20fa228e7c6215718e25 Mon Sep 17 00:00:00 2001 From: Luuk van der Meer Date: Wed, 22 Mar 2023 15:14:05 +0100 Subject: [PATCH 5/6] release: Update changelog and cran comments :bookmark: --- NEWS.md | 8 ++++++++ cran-comments.md | 11 +++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index fc1d64c7..0c969dd6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# sfnetworks v0.6.3 + +### Bug fixes + +* Argument names of sfnetwork S3 methods for `sf::st_geometry()`, `sf::st_bbox()`, `sf::st_m_range()` and `sf::st_set_precision()` are updated to be consistent with their corresponding generic functions in sf. +* Arguments `active` and `...` are removed from the sfnetwork S3 method for `sf::st_precision()` to be consistent with its corresponding generic function in sf. +* Argument `active` is removed from the sfnetwork S3 method for `sf::st_crs()` to be consistent with the above-mentioned change regarding `sf::st_precision()` (since both CRS and precision can not differ between nodes and edges). + # sfnetworks v0.6.2 ### Bug fixes diff --git a/cran-comments.md b/cran-comments.md index bbc1137f..2143b65f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,11 +1,10 @@ In this release we have made the following changes: -* The reference to `sf:::agr_levels` is removed, solving the note in the CRAN checks about the usage of the `:::` operator. -* Unit tests that where failing after an igraph update now run successfully again. Refs [#232](https://github.com/luukvdmeer/sfnetworks/issues/232). This means the CRAN checks that where failing should now be passing successfully again. -* Unit test stuck in an infinite loop caused by usage of `sf::st_sample()` on a polygon crossing the date line updated accordingly. See [this sf issue](https://github.com/r-spatial/sf/issues/1984) for details on the underlying problem. -* The `to_spatial_contracted()` morpher now correctly handles cases for undirected networks in which only loop edges are created after contraction. Refs [#237](https://github.com/luukvdmeer/sfnetworks/issues/237). -* The `to_spatial_contracted()` morpher now directly returns the original network when none of the contraction groups contain more than one node. -* Umbrella packages tidyverse and spatstat are no longer suggested packages. Only individual members of these packages are now suggested packages. +* Argument names of sfnetwork S3 methods for `sf::st_geometry()`, `sf::st_bbox()`, `sf::st_m_range()` and `sf::st_set_precision()` are updated to be consistent with their corresponding generic functions in sf. +* Arguments `active` and `...` are removed from the sfnetwork S3 method for `sf::st_precision()` to be consistent with its corresponding generic function in sf. +* Argument `active` is removed from the sfnetwork S3 method for `sf::st_crs()` to be consistent with the above-mentioned change regarding `sf::st_precision()` (since both CRS and precision can not differ between nodes and edges). + +These changes solve the warnings in the CRAN checks regarding S3 method consistency. ## R CMD check results From d9b5ad2e2e1182be2aa53907bfbd197fb3a70870 Mon Sep 17 00:00:00 2001 From: Luuk van der Meer Date: Wed, 22 Mar 2023 17:07:04 +0100 Subject: [PATCH 6/6] release: Update cran comments :bookmark: --- cran-comments.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cran-comments.md b/cran-comments.md index 2143b65f..802667c8 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -10,6 +10,15 @@ These changes solve the warnings in the CRAN checks regarding S3 method consiste 0 errors | 0 warnings | 0 notes +When running checks on R-hub, the following note occured only on Windows (Server 2022, R-devel 64-bit): + +``` +* checking for detritus in the temp directory ... NOTE +Found the following files/directories: + 'lastMiKTeXException' +``` +As noted in [R-hub issue #503](https://github.com/r-hub/rhub/issues/503), this is a bug in R-hub rather than a bug in our package, and can likely be ignored. + ## revdepcheck results We checked 1 reverse dependencies (0 from CRAN + 1 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.