luukvdmeer / sfnetworks

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

Network cleaning: to_spatial_contracted returns mapply error #237

Closed dpriss closed 1 year ago

dpriss commented 1 year ago

Hello, I've followed the steps for network pre-processing and network cleaning from this tutorial https://luukvdmeer.github.io/sfnetworks/articles/sfn02_preprocess_clean.html and everything works fine except the last bit when trying to contract the network, i.e.:

contracted = convert( clustered, to_spatial_contracted, cls, cmp, simplify = TRUE )

Here, I always get the error

Error in mapply(append_source, E2, N2, SIMPLIFY = FALSE) : object 'E2' not found

I tried it with different input data sets (.shp), including the toy data provided in the tutorial, but the error comes up with all of them.

Here's my sessionInfo() in case that's helpful:

R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] plyr_1.8.8 dbscan_1.1-11 forcats_0.5.2 stringr_1.4.1 purrr_0.3.5 readr_2.1.3 tidyr_1.2.1 tibble_3.1.8
[9] tidyverse_1.3.2 tidygraph_1.2.3 sfnetworks_0.6.1 igraph_1.3.5 plotly_4.10.1 ggplot2_3.4.0 sfheaders_0.4.0 dplyr_1.0.10
[17] sf_1.0-9

loaded via a namespace (and not attached): [1] httr_1.4.4 jsonlite_1.8.3 viridisLite_0.4.1 modelr_0.1.10 assertthat_0.2.1 sp_1.5-1 googlesheets4_1.0.1 [8] cellranger_1.1.0 pillar_1.8.1 backports_1.4.1 lattice_0.20-45 glue_1.6.2 digest_0.6.30 rvest_1.0.3
[15] colorspace_2.0-3 htmltools_0.5.3 pkgconfig_2.0.3 broom_1.0.1 raster_3.6-11 haven_2.5.1 scales_1.2.1
[22] terra_1.6-41 tzdb_0.3.0 timechange_0.1.1 proxy_0.4-27 googledrive_2.0.0 generics_0.1.3 farver_2.1.1
[29] ellipsis_0.3.2 withr_2.5.0 lazyeval_0.2.2 cli_3.4.1 magrittr_2.0.3 crayon_1.5.2 readxl_1.4.1
[36] fs_1.5.2 fansi_1.0.3 xml2_1.3.3 lwgeom_0.2-10 class_7.3-20 tools_4.2.2 data.table_1.14.4
[43] hms_1.1.2 gargle_1.2.1 lifecycle_1.0.3 munsell_0.5.0 reprex_2.0.2 compiler_4.2.2 e1071_1.7-12
[50] rlang_1.0.6 classInt_0.4-8 units_0.8-0 grid_4.2.2 rstudioapi_0.14 htmlwidgets_1.5.4 gtable_0.3.1
[57] codetools_0.2-18 DBI_1.1.3 R6_2.5.1 lubridate_1.9.0 fastmap_1.1.0 utf8_1.2.2 KernSmooth_2.23-20 [64] stringi_1.7.8 Rcpp_1.0.9 vctrs_0.5.0 dbplyr_2.2.1 tidyselect_1.2.0

Any idea why I get this error and how to solve it? Many thanks!

Deborah

agila5 commented 1 year ago

Hi Deborah and thanks for your question. Could you please create a reproducible example showing the error? Do you get any other error or warning before that last bit of code? I can run the code in the vignette without any problem, so it's quite difficult to diagnose the problem.

dpriss commented 1 year ago

Hi Andrea, thanks for getting back to me so quickly. I think I just found out what the problem is: In the vignette, one of the first steps is to round the geometry but when I do it, I get the error message when trying to use to_spatial_contracted later. If I don't round the geometry, everything works fine.

luukvdmeer commented 1 year ago

Thanks for reporting! After some trying I could reproduce the error. This seemed indeed like a bug (there was no fallback when no edges other than loop edges needed to be updated after contraction). It should be fixed now on Github (and in the minor version update on its way to CRAN asap).

dpriss commented 1 year ago

Great, thank you!