0

i have multiple trees (that are more path). so basicaly each node are connected with a direction to one path or none. i want to know for each of them the ultimate descendants ( that could be himself).

i try to do it with tidygraph.

demo_netw <- tbl_graph(nodes = tibble(name = c("A", "B", "C", "D")),
                       edges = tribble(~from, ~to,
                                       "A", "B",
                                       "B", "C"))
  demo_netw%>%
  activate(nodes) %>% 
  mutate(debut=(node_is_leaf()|node_is_isolated()),
         last_desc= map_bfs_back_chr(node_is_root(), unreachable = TRUE,
                                 .f = function(node, path,parent, ...) {
                                   if (.N()$debut[node]){
                                     return(.N()$name[node])
                                   }else {
                                     return(path$result[path$node==parent])
                                   }
                                 }
  )
  )

but it don't work. i have this

Error in `mutate()`:
i In argument: `last_desc = map_bfs_back_chr(...)`.
Caused by error in `as_vector()`:
! Cannot coerce values to <character(1)>

how can i d0o it.

francois
  • 135
  • 3
  • 9

0 Answers0