From 96e0a8cedbe3c2b31d84bc58808f153214fab8c8 Mon Sep 17 00:00:00 2001 From: Vincent Traag Date: Tue, 19 Dec 2023 10:20:47 +0100 Subject: [PATCH 1/9] improve: Rename resolution_parameter to resolution --- R/community.R | 12 ++++++------ tests/testthat/test-leiden.R | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/community.R b/R/community.R index 190f7981691..5de7f294243 100644 --- a/R/community.R +++ b/R/community.R @@ -1287,7 +1287,7 @@ cluster_spinglass <- function(graph, weights = NULL, vertex = NULL, spins = 25, #' weights. Set this to `NA` if the graph was a \sQuote{weight} edge #' attribute, but you don't want to use it for community detection. A larger #' edge weight means a stronger connection for this function. -#' @param resolution_parameter The resolution parameter to use. Higher +#' @param resolution The resolution parameter to use. Higher #' resolutions lead to more smaller communities, while lower resolutions lead #' to fewer larger communities. #' @param beta Parameter affecting the randomness in the Leiden algorithm. @@ -1330,11 +1330,11 @@ cluster_spinglass <- function(graph, weights = NULL, vertex = NULL, spins = 25, #' r <- quantile(strength(g))[2] / (gorder(g) - 1) #' # Set seed for sake of reproducibility #' set.seed(1) -#' ldc <- cluster_leiden(g, resolution_parameter = r) +#' ldc <- cluster_leiden(g, resolution = r) #' print(ldc) #' plot(ldc, g) cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), - weights = NULL, resolution_parameter = 1, beta = 0.01, + weights = NULL, resolution = 1, beta = 0.01, initial_membership = NULL, n_iterations = 2, vertex_weights = NULL) { ensure_igraph(graph) @@ -1373,7 +1373,7 @@ cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), # Set correct node weights vertex_weights <- strength(graph, weights = weights) # Also correct resolution parameter - resolution_parameter <- resolution_parameter / sum(vertex_weights) + resolution <- resolution / sum(vertex_weights) } } @@ -1382,7 +1382,7 @@ cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), if (n_iterations > 0) { res <- .Call( R_igraph_community_leiden, graph, weights, - vertex_weights, as.numeric(resolution_parameter), + vertex_weights, as.numeric(resolution), as.numeric(beta), !is.null(membership), as.numeric(n_iterations), membership ) @@ -1394,7 +1394,7 @@ cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), prev_quality <- quality res <- .Call( R_igraph_community_leiden, graph, weights, - vertex_weights, as.numeric(resolution_parameter), + vertex_weights, as.numeric(resolution), as.numeric(beta), !is.null(membership), 1, membership ) diff --git a/tests/testthat/test-leiden.R b/tests/testthat/test-leiden.R index 4eccfeed18a..5185929cdbb 100644 --- a/tests/testthat/test-leiden.R +++ b/tests/testthat/test-leiden.R @@ -2,7 +2,7 @@ test_that("cluster_leiden works", { withr::local_seed(42) g <- make_graph("Zachary") - mc <- cluster_leiden(g, resolution_parameter = 0.06) + mc <- cluster_leiden(g, resolution = 0.06) expect_that( as.vector(membership(mc)), From b27f0e2639b44f55a3aa6cba7df62044deae47d8 Mon Sep 17 00:00:00 2001 From: Vincent Traag Date: Tue, 19 Dec 2023 15:58:52 +0100 Subject: [PATCH 2/9] fix: Add deprecation of resolution_parameter --- R/community.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/R/community.R b/R/community.R index 5de7f294243..63375934299 100644 --- a/R/community.R +++ b/R/community.R @@ -1334,8 +1334,18 @@ cluster_spinglass <- function(graph, weights = NULL, vertex = NULL, spins = 25, #' print(ldc) #' plot(ldc, g) cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), - weights = NULL, resolution = 1, beta = 0.01, - initial_membership = NULL, n_iterations = 2, vertex_weights = NULL) { + weights = NULL, resolution = 1, + resolution_parameter = deprecated(), beta = 0.01, + initial_membership = NULL, + n_iterations = 2, vertex_weights = NULL) { + + if (lifecycle::is_present(resolution_parameter)) { + lifecycle::deprecate_warn("1.5.0.9006", + "cluster_leiden(resolution_parameter)", + "cluster_leiden(resolution)") + resolution <- resolution_parameter + } + ensure_igraph(graph) # Parse objective function argument From 19eaaeb832581b7cab52bacc292417028379f8c5 Mon Sep 17 00:00:00 2001 From: Vincent Traag Date: Tue, 19 Dec 2023 16:42:43 +0100 Subject: [PATCH 3/9] fix: Change to deprecate_soft --- R/community.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/community.R b/R/community.R index 63375934299..8abba05019a 100644 --- a/R/community.R +++ b/R/community.R @@ -1340,7 +1340,7 @@ cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), n_iterations = 2, vertex_weights = NULL) { if (lifecycle::is_present(resolution_parameter)) { - lifecycle::deprecate_warn("1.5.0.9006", + lifecycle::deprecate_soft("1.5.0.9006", "cluster_leiden(resolution_parameter)", "cluster_leiden(resolution)") resolution <- resolution_parameter From b52a9ca73aebe5768e43a1d4e5d4e3b26be3e65d Mon Sep 17 00:00:00 2001 From: Vincent Traag Date: Tue, 19 Dec 2023 21:47:14 +0100 Subject: [PATCH 4/9] doc: Updated cluster_leiden for change of argument --- man/cluster_leiden.Rd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/man/cluster_leiden.Rd b/man/cluster_leiden.Rd index c1d903b3666..4cb2651e660 100644 --- a/man/cluster_leiden.Rd +++ b/man/cluster_leiden.Rd @@ -9,7 +9,8 @@ cluster_leiden( graph, objective_function = c("CPM", "modularity"), weights = NULL, - resolution_parameter = 1, + resolution = 1, + resolution_parameter = deprecated(), beta = 0.01, initial_membership = NULL, n_iterations = 2, @@ -30,7 +31,7 @@ weights. Set this to \code{NA} if the graph was a \sQuote{weight} edge attribute, but you don't want to use it for community detection. A larger edge weight means a stronger connection for this function.} -\item{resolution_parameter}{The resolution parameter to use. Higher +\item{resolution}{The resolution parameter to use. Higher resolutions lead to more smaller communities, while lower resolutions lead to fewer larger communities.} @@ -105,7 +106,7 @@ g <- make_graph("Zachary") r <- quantile(strength(g))[2] / (gorder(g) - 1) # Set seed for sake of reproducibility set.seed(1) -ldc <- cluster_leiden(g, resolution_parameter = r) +ldc <- cluster_leiden(g, resolution = r) print(ldc) plot(ldc, g) } From 62271d22d48b9223af53607a8c5e5e43e92b479c Mon Sep 17 00:00:00 2001 From: Vincent Traag Date: Fri, 12 Jan 2024 15:32:10 +0100 Subject: [PATCH 5/9] fix: Retain old argument, but mark as superseded. --- R/community.R | 1 + man/cluster_leiden.Rd | 2 ++ 2 files changed, 3 insertions(+) diff --git a/R/community.R b/R/community.R index 8abba05019a..605f9be192e 100644 --- a/R/community.R +++ b/R/community.R @@ -1290,6 +1290,7 @@ cluster_spinglass <- function(graph, weights = NULL, vertex = NULL, spins = 25, #' @param resolution The resolution parameter to use. Higher #' resolutions lead to more smaller communities, while lower resolutions lead #' to fewer larger communities. +#' @param resolution_parameter `r lifecycle::badge("superseded")` Use `resolution` instead. #' @param beta Parameter affecting the randomness in the Leiden algorithm. #' This affects only the refinement step of the algorithm. #' @param initial_membership If provided, the Leiden algorithm diff --git a/man/cluster_leiden.Rd b/man/cluster_leiden.Rd index 4cb2651e660..080a890d477 100644 --- a/man/cluster_leiden.Rd +++ b/man/cluster_leiden.Rd @@ -35,6 +35,8 @@ edge weight means a stronger connection for this function.} resolutions lead to more smaller communities, while lower resolutions lead to fewer larger communities.} +\item{resolution_parameter}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} Use \code{resolution} instead.} + \item{beta}{Parameter affecting the randomness in the Leiden algorithm. This affects only the refinement step of the algorithm.} From 51cc64d907ff816d65f2ab3193901ca6532fc6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 14 May 2024 14:13:20 +0200 Subject: [PATCH 6/9] tweaks --- R/community.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/community.R b/R/community.R index 605f9be192e..a0d7d96996d 100644 --- a/R/community.R +++ b/R/community.R @@ -1335,11 +1335,16 @@ cluster_spinglass <- function(graph, weights = NULL, vertex = NULL, spins = 25, #' print(ldc) #' plot(ldc, g) cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), + ..., weights = NULL, resolution = 1, - resolution_parameter = deprecated(), beta = 0.01, + # FIXME: change to deprecated() once we have @importFrom lifecycle deprecated, + # after igraph:::deprecated() is removed + resolution_parameter, beta = 0.01, initial_membership = NULL, n_iterations = 2, vertex_weights = NULL) { + check_dots_empty() + if (lifecycle::is_present(resolution_parameter)) { lifecycle::deprecate_soft("1.5.0.9006", "cluster_leiden(resolution_parameter)", From 8f5894361a767194e04bc0f17f7f863509df3fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 17 May 2024 13:08:37 +0200 Subject: [PATCH 7/9] doc --- man/cluster_leiden.Rd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/man/cluster_leiden.Rd b/man/cluster_leiden.Rd index 080a890d477..1b5bb44787c 100644 --- a/man/cluster_leiden.Rd +++ b/man/cluster_leiden.Rd @@ -8,9 +8,10 @@ van Eck & Waltman.} cluster_leiden( graph, objective_function = c("CPM", "modularity"), + ..., weights = NULL, resolution = 1, - resolution_parameter = deprecated(), + resolution_parameter, beta = 0.01, initial_membership = NULL, n_iterations = 2, From 2d045c24cc0ea340d2a14031336fd03519319550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Thu, 23 May 2024 13:12:58 +0200 Subject: [PATCH 8/9] fix: fix docs --- R/community.R | 3 ++- man/cluster_leiden.Rd | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/community.R b/R/community.R index a0d7d96996d..3aa414879fb 100644 --- a/R/community.R +++ b/R/community.R @@ -1302,6 +1302,7 @@ cluster_spinglass <- function(graph, weights = NULL, vertex = NULL, spins = 25, #' If this is not provided, it will be automatically determined on the basis #' of the `objective_function`. Please see the details of this function #' how to interpret the vertex weights. +#' @inheritParams rlang::args_dots_empty #' @return `cluster_leiden()` returns a [communities()] #' object, please see the [communities()] manual page for details. #' @author Vincent Traag @@ -1346,7 +1347,7 @@ cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), check_dots_empty() if (lifecycle::is_present(resolution_parameter)) { - lifecycle::deprecate_soft("1.5.0.9006", + lifecycle::deprecate_soft("2.0.3", "cluster_leiden(resolution_parameter)", "cluster_leiden(resolution)") resolution <- resolution_parameter diff --git a/man/cluster_leiden.Rd b/man/cluster_leiden.Rd index 1b5bb44787c..83f13a19c9e 100644 --- a/man/cluster_leiden.Rd +++ b/man/cluster_leiden.Rd @@ -24,6 +24,8 @@ cluster_leiden( \item{objective_function}{Whether to use the Constant Potts Model (CPM) or modularity. Must be either \code{"CPM"} or \code{"modularity"}.} +\item{...}{These dots are for future extensions and must be empty.} + \item{weights}{The weights of the edges. It must be a positive numeric vector, \code{NULL} or \code{NA}. If it is \code{NULL} and the input graph has a \sQuote{weight} edge attribute, then that attribute will be used. If From c04b6fae7ead59c0c905560e31633120c4630e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 4 Jun 2024 11:44:57 +0200 Subject: [PATCH 9/9] change version number --- R/community.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/community.R b/R/community.R index 3aa414879fb..297154db1ca 100644 --- a/R/community.R +++ b/R/community.R @@ -1347,7 +1347,7 @@ cluster_leiden <- function(graph, objective_function = c("CPM", "modularity"), check_dots_empty() if (lifecycle::is_present(resolution_parameter)) { - lifecycle::deprecate_soft("2.0.3", + lifecycle::deprecate_soft("2.0.4", "cluster_leiden(resolution_parameter)", "cluster_leiden(resolution)") resolution <- resolution_parameter