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", 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/R/sf.R b/R/sf.R index 1f36fd16..a83b7192 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 @@ -95,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), ...) } # ============================================================================= @@ -118,8 +117,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 @@ -147,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(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") - switch( - active, - nodes = st_bbox(pull_node_geom(x), ...), - edges = st_bbox(pull_edge_geom(x), ...), - raise_unknown_input(active) - ) +st_bbox.sfnetwork = function(obj, active = NULL, ...) { + 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), ...) } # ============================================================================= @@ -199,14 +184,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 @@ -226,27 +205,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) } @@ -286,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(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") - switch( - active, - nodes = st_m_range(pull_node_geom(x), ...), - edges = st_m_range(pull_edge_geom(x), ...), - raise_unknown_input(active) - ) +st_m_range.sfnetwork = function(obj, active = NULL, ...) { + 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(x, active = NULL, ...) { - if (is.null(active)) active = attr(x, "active") - switch( - active, - nodes = st_z_range(pull_node_geom(x), ...), - edges = st_z_range(pull_edge_geom(x), ...), - raise_unknown_input(active) - ) +st_z_range.sfnetwork = function(obj, active = NULL, ...) { + st_z_range(pull_geom(obj, active), ...) } change_coords = function(x, op, ...) { @@ -337,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 @@ -779,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), ...) } } @@ -791,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), ...) } diff --git a/cran-comments.md b/cran-comments.md index bbc1137f..802667c8 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,16 +1,24 @@ 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 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. 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..dc060d87 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, ...) @@ -60,13 +60,13 @@ \method{st_is_valid}{sfnetwork}(x, ...) -\method{st_crs}{sfnetwork}(x, active = NULL, ...) +\method{st_crs}{sfnetwork}(x, ...) \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