luukvdmeer / sfnetworks

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

add_edges and add_vertices break with geometry columns #49

Closed luukvdmeer closed 3 years ago

luukvdmeer commented 4 years ago

Describe the bug Before, the bind functionalities of tidygraph (i.e. bind_graphs, bind_nodes and bind_edges) did not work for sfnetwork objects because bind_rows of dplyr did not work for sf objects. With the development versions of dplyr (1.0.0.9000), vctrs (0.3.1.9000) and sf (0.9-4), this problem is solved. That makes that bind_graphs now works good for sfnetwork objects:

library(sfnetworks)

sn = as_sfnetwork(roxel, directed = FALSE)

c(igraph::vcount(sn), igraph::ecount(sn))
#> 701 851

snb = tidygraph::bind_graphs(sn, sn)

c(igraph::vcount(snb), igraph::ecount(snb))
#> 1402 1702

However, bind_nodes still fails, because of a new, weird error:

nsf = sf::st_as_sf(sn)

tidygraph::bind_nodes(sn, nsf)
#> Error in UseMethod("st_bbox") : 
#>  no applicable method for 'st_bbox' applied to an object of class "logical"

The error is caused by igraph::add_vertices, which is used internally in bind_nodes. It is a mystery for me why that function would call st_bbox, but I did not look into it yet. What I did find is that the same error occurs when using as_tibble(nsf) instead of nsf, so it is really the geometry list column that causes the problem, not just the sf class.

For edges (i.e. using tidygraph::bind_edges) RStudio even crashes completely (i.e. aborted because of fatal error). Here, the error is caused by igraph::add_edges.

The add_vertices and add_edges functions are also used inside right joins and full joins, which also fail.

R Session Info

sessionInfo()
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 16.04.6 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/libblas/libblas.so.3.6.0
#> LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=de_AT.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=de_AT.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=de_AT.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=de_AT.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] igraph_1.2.5     sf_0.9-4         tidygraph_1.2.0  dplyr_1.0.0.9000
#> [5] sfnetworks_0.2.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.4.6       rstudioapi_0.11    magrittr_1.5      
#>  [4] units_0.6-6        tidyselect_1.1.0   R6_2.4.1          
#>  [7] rlang_0.4.6.9000   fansi_0.4.1        tools_3.6.3       
#> [10] grid_3.6.3         utf8_1.1.4         KernSmooth_2.23-17
#> [13] cli_2.0.2          e1071_1.7-3        DBI_1.1.0         
#> [16] ellipsis_0.3.1     class_7.3-16       assertthat_0.2.1  
#> [19] tibble_3.0.1       lwgeom_0.2-4       lifecycle_0.2.0   
#> [22] crayon_1.3.4       tidyr_1.0.2        purrr_0.3.4       
#> [25] vctrs_0.3.1.9000   glue_1.4.1         compiler_3.6.3    
#> [28] pillar_1.4.4       generics_0.0.2     classInt_0.4-3    
#> [31] pkgconfig_2.0.3  
luukvdmeer commented 3 years ago

Functions that fail because of this bug (as far as I know of):

luukvdmeer commented 3 years ago

This is not really an sfnetworks issue. It is now documented in #29