Skip to content

Commit

Permalink
feat: Add message argument to sfnetwork constructor. Refs #261 🎁
Browse files Browse the repository at this point in the history
  • Loading branch information
luukvdmeer committed Apr 9, 2024
1 parent 4602e10 commit 6a15113
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions R/sfnetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
#' your input data meet the requirements, the checks are unnecessary and can be
#' turned off to improve performance.
#'
#' @param message Should informational messages (those messages that are
#' neither warnings nor errors) be printed when constructing the network?
#' Defaults to \code{TRUE}.
#'
#' @param ... Arguments passed on to \code{\link[sf]{st_as_sf}}, if nodes need
#' to be converted into an \code{\link[sf]{sf}} object during construction.
#'
Expand Down Expand Up @@ -102,7 +106,7 @@
#' @export
sfnetwork = function(nodes, edges = NULL, directed = TRUE, node_key = "name",
edges_as_lines = NULL, length_as_weight = FALSE,
force = FALSE, ...) {
force = FALSE, message = TRUE, ...) {
# Prepare nodes.
# If nodes is not an sf object:
# --> Try to convert it to an sf object.
Expand Down Expand Up @@ -140,12 +144,12 @@ sfnetwork = function(nodes, edges = NULL, directed = TRUE, node_key = "name",
# --> Adding additional attributes if requested.
if (is.null(edges)) {
# Run validity check for nodes only and return the network.
if (! force) require_valid_network_structure(x_sfn, message = TRUE)
if (! force) require_valid_network_structure(x_sfn, message = message)
return (x_sfn)
}
if (edges_as_lines) {
# Run validity check before explicitizing edges.
if (! force) require_valid_network_structure(x_sfn, message = TRUE)
if (! force) require_valid_network_structure(x_sfn, message = message)
# Add edge geometries if needed.
if (edges_are_explicit) {
# Edges already have geometries, we don't need to add them.
Expand All @@ -163,7 +167,7 @@ sfnetwork = function(nodes, edges = NULL, directed = TRUE, node_key = "name",
x_sfn = implicitize_edges(x_sfn)
}
# Run validity check after implicitizing edges.
if (! force) require_valid_network_structure(x_sfn, message = TRUE)
if (! force) require_valid_network_structure(x_sfn, message = message)
}
if (length_as_weight) {
edges = edges_as_sf(x_sfn)
Expand Down
5 changes: 5 additions & 0 deletions man/sfnetwork.Rd

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

0 comments on commit 6a15113

Please sign in to comment.