luukvdmeer / sfnetworks

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

sfnetwork class is duplicated with spatial morphers #121

Closed agila5 closed 3 years ago

agila5 commented 3 years ago

Describe the bug The sfnetwork class that characterise each sfnetwork object is duplicated every time I apply a spatial morpher. I think it has no real consequences on the code but it is, IMO, an unexpected behaviour. I didn't test all morphers.

Reproducible example

# packages
library(sfnetworks)
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter

# data
sfn <- as_sfnetwork(roxel)
class(sfn)
#> [1] "sfnetwork" "tbl_graph" "igraph"

sfn2 <- convert(sfn, to_spatial_subdivision, .clean = TRUE)
#> Warning: to_spatial_subdivision assumes attributes are constant over geometries
class(sfn2) # sfnetwork is duplicated
#> [1] "sfnetwork" "sfnetwork" "tbl_graph" "igraph"

sfn3 <- convert(sfn2, to_components, .clean = TRUE, .select = 1)
class(sfn3) # OK
#> [1] "sfnetwork" "sfnetwork" "tbl_graph" "igraph"

sfn4 <- convert(sfn3, to_spatial_smooth, .clean = TRUE)
class(sfn4) # sfnetwork is duplicated
#> [1] "sfnetwork" "sfnetwork" "sfnetwork" "sfnetwork" "tbl_graph" "igraph"

Created on 2021-02-04 by the reprex package (v0.3.0)

Expected behaviour No duplication.

R Session Info

Session info ``` r devtools::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 3.6.3 (2020-02-29) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate Italian_Italy.1252 #> ctype Italian_Italy.1252 #> tz Europe/Berlin #> date 2021-02-04 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) #> callr 3.5.1 2020-10-13 [1] CRAN (R 3.6.3) #> class 7.3-17 2020-04-26 [1] CRAN (R 3.6.3) #> classInt 0.4-3 2020-04-07 [1] CRAN (R 3.6.3) #> cli 2.2.0 2020-11-20 [1] CRAN (R 3.6.3) #> colorspace 2.0-0 2020-11-11 [1] CRAN (R 3.6.3) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) #> DBI 1.1.1 2021-01-15 [1] CRAN (R 3.6.3) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) #> devtools 2.3.2 2020-09-18 [1] CRAN (R 3.6.3) #> digest 0.6.27 2020-10-24 [1] CRAN (R 3.6.3) #> dplyr 1.0.3 2021-01-15 [1] CRAN (R 3.6.3) #> e1071 1.7-4 2020-10-14 [1] CRAN (R 3.6.3) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 3.6.3) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) #> fansi 0.4.2 2021-01-15 [1] CRAN (R 3.6.3) #> fs 1.5.0 2020-07-31 [1] CRAN (R 3.6.3) #> generics 0.1.0 2020-10-31 [1] CRAN (R 3.6.3) #> ggplot2 3.3.2 2020-06-19 [1] CRAN (R 3.6.3) #> glue 1.4.2 2020-08-27 [1] CRAN (R 3.6.3) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0) #> htmltools 0.5.0 2020-06-16 [1] CRAN (R 3.6.3) #> igraph 1.2.6 2020-10-06 [1] CRAN (R 3.6.3) #> KernSmooth 2.23-18 2020-10-29 [1] CRAN (R 3.6.3) #> knitr 1.30 2020-09-22 [1] CRAN (R 3.6.3) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 3.6.2) #> lwgeom 0.2-5 2020-06-12 [1] CRAN (R 3.6.3) #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 3.6.3) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0) #> pillar 1.4.7 2020-11-20 [1] CRAN (R 3.6.3) #> pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 3.6.3) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) #> pkgload 1.1.0 2020-05-29 [1] CRAN (R 3.6.3) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2) #> processx 3.4.4 2020-09-03 [1] CRAN (R 3.6.3) #> ps 1.4.0 2020-10-07 [1] CRAN (R 3.6.3) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 3.6.3) #> R6 2.5.0 2020-10-28 [1] CRAN (R 3.6.3) #> Rcpp 1.0.6 2021-01-15 [1] CRAN (R 3.6.3) #> remotes 2.2.0 2020-07-21 [1] CRAN (R 3.6.3) #> rlang 0.4.10 2020-12-30 [1] CRAN (R 3.6.3) #> rmarkdown 2.5 2020-10-21 [1] CRAN (R 3.6.3) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 3.6.3) #> scales 1.1.1 2020-05-11 [1] CRAN (R 3.6.3) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) #> sf 0.9-7 2021-01-06 [1] CRAN (R 3.6.3) #> sfheaders 0.4.0 2020-12-01 [1] CRAN (R 3.6.3) #> sfnetworks * 0.5.0 2021-02-04 [1] local #> stringi 1.5.3 2020-09-09 [1] CRAN (R 3.6.3) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) #> testthat 3.0.0 2020-10-31 [1] CRAN (R 3.6.3) #> tibble 3.0.6 2021-01-29 [1] CRAN (R 3.6.3) #> tidygraph * 1.2.0 2020-05-12 [1] CRAN (R 3.6.3) #> tidyr 1.1.2 2020-08-27 [1] CRAN (R 3.6.3) #> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 3.6.3) #> units 0.6-7 2020-06-13 [1] CRAN (R 3.6.3) #> usethis 2.0.0 2020-12-10 [1] CRAN (R 3.6.3) #> vctrs 0.3.6 2020-12-17 [1] CRAN (R 3.6.3) #> withr 2.3.0 2020-09-22 [1] CRAN (R 3.6.3) #> xfun 0.19 2020-10-30 [1] CRAN (R 3.6.3) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2) #> #> [1] C:/Users/Utente/Documents/R/win-library/3.6 #> [2] C:/Program Files/R/R-3.6.3/library ```
agila5 commented 3 years ago

I'm not super familiar with the morphing workflow, but I think we just need to modify the following code:

https://github.com/luukvdmeer/sfnetworks/blob/eafe522abbfe59551fbc3a452cff73dc289ac4c9/R/sfnetwork.R#L168-L175

luukvdmeer commented 3 years ago

This is indeed a bug, caused by the internal function morphed_tbg_to_morphed_sfn. Will be fixed in the next push. Thanks!