luukvdmeer / sfnetworks

Tidy Geospatial Networks in R
https://luukvdmeer.github.io/sfnetworks/
Other
334 stars 20 forks source link

Adopt a more explicit error message when running edge_length (and related function) with active nodes #216

Closed agila5 closed 1 year ago

agila5 commented 2 years ago

Describe the bug I think the error when running edge_length with active nodes could be more explicit. For example, we could copy the same workflow as in tidygraph.

Reproducible example

library(sfnetworks)
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter
sfn <- as_sfnetwork(roxel)
# Unclear error
sfn %>% 
  arrange(edge_length())
#> Error in `st_as_sf()`:
#> ! Problem with the implicit `transmute()` step.
#> ✖ Problem while computing `..1 = edge_length()`.
#> ✖ `..1` must be size 701 or 1, not 851.

# Better explanation
sfn %>% 
  filter(edge_is_loop())
#> Error in `stopifnot()`:
#> ! Problem while computing `..1 = edge_is_loop()`.
#> Caused by error in `expect_edges()`:
#> ! This call requires edges to be active

Created on 2022-06-27 by the reprex package (v2.0.1)

Expected behavior A better error message

R Session Info (Will add later)

luukvdmeer commented 1 year ago

Implemented in v0.6.0. The message is now:

This call requires edges to be active

Just as in tidygraph. Similar error message is printed for the node_* functions when nodes are not active.