luukvdmeer / sfnetworks

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

Passing an unexisting column as a weigths argument in st_network_paths does not throw an error #99

Closed loreabad6 closed 3 years ago

loreabad6 commented 3 years ago

Describe the bug When passing a character string in st_network_paths(weights = 'invented_string'), the algorithm runs normally assuming NULL weights.

Reproducible example

library(sfnetworks)
(net = roxel %>% 
  as_sfnetwork() %>% 
  activate('edges'))
#> # A sfnetwork with 701 nodes and 851 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # A directed multigraph with 14 components with spatially explicit edges
#> #
#> # Edge Data:     851 x 5 (active)
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>    from    to name         type                                         geometry
#>   <int> <int> <chr>        <fct>                                <LINESTRING [°]>
#> 1     1     2 Havixbecker~ reside~        (7.533722 51.95556, 7.533461 51.95576)
#> 2     3     4 Pienersallee second~ (7.532442 51.95422, 7.53236 51.95377, 7.5320~
#> 3     5     6 Schulte-Ber~ reside~ (7.532709 51.95209, 7.532823 51.95239, 7.532~
#> 4     7     8 <NA>         path    (7.540063 51.94468, 7.539696 51.94479, 7.539~
#> 5     9    10 Welsingheide reside~         (7.537673 51.9475, 7.537614 51.94562)
#> 6    11    12 <NA>         footway (7.543791 51.94733, 7.54369 51.94686, 7.5437~
#> # ... with 845 more rows
#> #
#> # Node Data:     701 x 1
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>              geometry
#>           <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> # ... with 698 more rows

net %>% 
  st_network_paths(8, 13, weights = 'invented_string')
#> # A tibble: 1 x 2
#>   node_paths edge_paths
#>   <list>     <list>    
#> 1 <int [11]> <int [10]>

Expected behavior This should throw an error.

luukvdmeer commented 3 years ago

Yes, this should give an error. The function searches for an edge attribute named 'invented_string' and returns NULL if it cannot find it. That results in forwarding weights = NULL to the igraph function, which in turn results in using a 'weight' column if present and no weights otherwise.

Instead, we should give an error when it cannot find the requested edge attribute.