Closed chinhqho closed 5 months ago
That's just because dplyr
expects pure data.frame
or directly derived objects, but dodgr
produces its own special class of data.frame
objects:
library (dodgr)
graph <- weight_streetnet (hampi)
class (graph)
#> [1] "data.frame" "dodgr_streetnet"
class (as.data.frame (graph))
#> [1] "data.frame" "dodgr_streetnet"
class (tibble::as_tibble (graph))
#> [1] "tbl_df" "tbl" "data.frame"
Created on 2024-06-06 with reprex v2.1.0
Converting to tibble
removes the dodgr_streetnet
class information, and that will then prevent dodgr functionality from working with the graph. This is perfectly standard S3 dispatch methodology, and just something you have to live with in R. It's up to users to strip the class information if they want to pass dodgr
graphs through dplyr
routines.
@mpadge, I can't get my head around why dplyr::mutate() function does not work on an object of
data.frame
anddodgr_streetnet
class. Below is a reproducible example.Error in
vec_data()
: !x
must be a vector, not a <data.frame/dodgr_streetnet> object. Backtrace:Replacing the
as.data.frame()
withas_tibble()
works. I don't want to convert the graph to tibble because I just need to aggregate the flows after parallel processing multiple sets of froms and tos on the same graph dataset - then use other dodgr functions such asmerge_directed_graph
to work with graph1.