Closed agila5 closed 2 months ago
Thanks @agila5, and great to hear from you once again! That was very easy to fix, and doesn't affect anything here. That said, it it odd that I've never noticed anything not working with dplyr
, because as far as I knew, that always followed NextMethod
anyway, so should always have dispatched on data.frame
alone. I only ever did stuff like this, which seemed fine (where this first code is previous version with class of c("data.frame", "dodgr_streetnet")
):
library (dodgr)
packageVersion ("dodgr")
#> [1] '0.4.1.17'
library (dplyr)
net <- weight_streetnet (hampi)
net |> group_by (way_id) |> summarise (d = sum (d))
#> # A tibble: 236 × 2
#> way_id d
#> <chr> <dbl>
#> 1 123463595 2620.
#> 2 123463598 9390.
#> 3 123463601 1359.
#> 4 126094049 2647.
#> 5 129323700 175.
#> 6 129323701 463.
#> 7 129325638 288.
#> 8 129325640 562.
#> 9 154318162 542.
#> 10 159460406 169.
#> # ℹ 226 more rows
But it does indeed error as you suggest:
net |> slice (1L)
#> Error in `vec_slice()`:
#> ! `x` must be a vector, not a <data.frame/dodgr_streetnet> object.
Whatever the reason for that, the changes you suggested now ensure that it all works as expected:
setwd ("/<local>/<path>/<to>/dodgr")
devtools::load_all (".", export_all = TRUE)
#> ℹ Loading dodgr
packageVersion ("dodgr")
#> [1] '0.4.1.26'
net <- weight_streetnet (hampi)
net |> slice (1L)
#> geom_num edge_id from_id from_lon from_lat to_id to_lon to_lat
#> 1 1 1 339318500 76.47491 15.34167 339318502 76.47612 15.34173
#> d d_weighted highway way_id component bicycle time time_weighted
#> 1 130.0002 144.4447 path 28565950 1 <NA> 39.00007 43.33341
Created on 2024-09-19 with reprex v2.1.1
So clearly an improvement, thanks to you!
Thanks! I think this is really useful since that also implies we can define st_as_sf.dodgr_streetnet
, as_sfnetwork.dodgr_streetnet
& friends.
Hi @mpadge, I hope you're doing well! It's been a while since I last created an issue here 😄
I'm opening this issue/discussion because I have a question regarding the definition of
dodgr_streetnet
objects, such as those created by theweight_streetnet()
function. Currently, theweight_streetnet()
function sets the class of the output by appending the"dodgr_streetnet"
string to the end of the class definition:https://github.com/UrbanAnalyst/dodgr/blob/13a6b38577cd67898144ab7ca138d42bbf3c6c6e/R/weight-streetnet.R#L307
This results in:
While this approach works, I believe it introduces some limitations. For example:
dplyr
verbs on"dodgr_streetnet"
objects:This issue could be resolved if
class(net)
were defined asc("dodgr_streetnet", "data.frame")
, which allows dplyr operations:Created on 2024-09-18 with reprex v2.0.2
"dodgr_streetnet"
when there is potential for conflict with"data.frame"
methods. See here for an example.Would you be open to considering a change to
c("dodgr_streetnet", "data.frame")
for future versions (perhaps dodgr v1.0)? I feel this approach better reflects the idea that "dodgr_streetnet" is a subclass of "data.frame", as described here.Looking forward to your thoughts on this!