Skip to content

Commit

Permalink
test for existance or from and to colnames when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Gilardi committed Jul 12, 2024
1 parent 2eb08cf commit 81d0e7c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/sfnetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ sfnetwork = function(nodes, edges = NULL, directed = TRUE, node_key = "name",
# --> Therefore it has to be converted into a regular data frame (or tibble).
edges_are_explicit = is.sf(edges)
if (edges_are_explicit) {
if (!force && !all(c("from", "to") %in% names(edges))) {
stop(
"Edges are spatially explicit, but 'from' and 'to' columns are missing",
call. = FALSE
)
}
edges_df = structure(edges, class = setdiff(class(edges), "sf"))
if (is.null(edges_as_lines)) edges_as_lines = TRUE
} else {
Expand Down

0 comments on commit 81d0e7c

Please sign in to comment.