Skip to content

Commit

Permalink
Add weights to graph_mean_dist
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Nov 17, 2023
1 parent 5d118be commit 1e0b64e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
now works with the tbl_graph constructors (#184)
* `graph_automorphisms()` gains a `color` argument in line with capabilities in
igraph
* `graph_mean_dist()` now supports edge weights through a new `weights` argument

# tidygraph 1.2.3

Expand Down
6 changes: 4 additions & 2 deletions R/graph_measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ graph_min_cut <- function(capacity = NULL) {
#' @describeIn graph_measures Calculates the mean distance between all node pairs in the graph. Wraps [igraph::mean_distance()]
#' @importFrom igraph mean_distance
#' @export
graph_mean_dist <- function(directed = TRUE, unconnected = TRUE) {
graph_mean_dist <- function(directed = TRUE, unconnected = TRUE, weights = NULL) {
graph <- .G()
mean_distance(graph, directed = directed, unconnected = unconnected)
weights <- enquo(weights)
weights <- eval_tidy(weights, .E())
mean_distance(graph, directed = directed, unconnected = unconnected, weights = weights)
}
#' @describeIn graph_measures Calculates the modularity of the graph contingent on a provided node grouping
#' @param group The node grouping to calculate the modularity on
Expand Down

0 comments on commit 1e0b64e

Please sign in to comment.