rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

feat: weight support for `eccentricity()` and `radius()`

Open szhorvat opened this issue 1 year ago • 11 comments

Fixes #893

szhorvat avatar Feb 06 '24 19:02 szhorvat

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes. Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged manually (without Aviator). Merging manually can negatively impact the performance of the queue. Consider using Aviator next time.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

aviator-app[bot] avatar Feb 06 '24 19:02 aviator-app[bot]

Waiting on https://github.com/igraph/stimulus/issues/7

szhorvat avatar Feb 06 '24 19:02 szhorvat

@maelle I need your help and advice here as this may require some lifecycle work.

This is a breaking change not just because of some changes to arguments, but also because the weight edge attribute is now used automatically, if present.

szhorvat avatar Feb 06 '24 19:02 szhorvat

some changes to arguments, but also because the weight edge attribute is now used automatically, if present.

What changes to arguments exactly?

Regarding the use of the attribute, how did user use to opt in? Could there be a way for users to still opt in?

maelle avatar Feb 09 '24 09:02 maelle

What changes to arguments exactly?

The weights parameter was added. It was not present previously.

mode now comes after ..., meaning that it must be used as a named argument, not as a positional one. radius(g, 'in') does not work anymore. One must use radius(g, mode='in').

Regarding the use of the attribute, how did user use to opt in? Could there be a way for users to still opt in?

It is a bad idea to make this opt-in as it creates inconsistencies and unpredictability in the long term. Let's not do that. If there is a weight attribute, and the function supports it, it should always be used automatically.

There's a way to opt out with weights=NA.

szhorvat avatar Feb 09 '24 13:02 szhorvat

How shall we proceed with this?

szhorvat avatar Feb 27 '24 11:02 szhorvat

I spoke too soon, this is actually a breaking change. Example for compatibility code:

diff --git a/R/community.R b/R/community.R
index dd1272ca36..7d9a0b83c4 100644
--- a/R/community.R
+++ b/R/community.R
@@ -677,7 +677,34 @@ modularity <- function(x, ...) {
 #' modularity(wtc)
 #' modularity(g, membership(wtc))
 #'
-modularity.igraph <- function(x, membership, weights = NULL, resolution = 1, directed = TRUE, ...) {
+modularity.igraph <- function(x, membership, ..., weights = NULL, resolution = 1, directed = TRUE) {
+
+  if (...length() > 0) {
+    lifecycle::deprecate_soft(
+      "3.0.0",
+      "modularity.igraph(... =)",
+      details = "The arguments `weights`, `resolution` and `directed` must be named."
+    )
+
+    dots <- list(...)
+    stopifnot(all(names2(dots) == ""))
+
+    if (is.null(weights) && length(dots) > 0) {
+      weights <- dots[[1]]
+      dots <- dots[-1]
+    }
+
+    if (missing(resolution) && length(dots) > 0) {
+      resolution <- dots[[1]]
+      dots <- dots[-1]
+    }
+
+    if (missing(directed) && length(dots) > 0) {
+      directed <- dots[[1]]
+      dots <- dots[-1]
+    }
+  }
+
   # Argument checks
   ensure_igraph(x)
   if (is.null(membership) || (!is.numeric(membership) && !is.factor(membership))) {

krlmlr avatar Mar 12 '24 13:03 krlmlr

Can you please add tests for the new functions?

I won't be able to do this this week, but I'm happy to do it next week.

Could you please handle the rest, i.e. deciding on the function signature, where the ... should go, how much of a breaking change we're willing to make?

szhorvat avatar Mar 12 '24 14:03 szhorvat

I'll come back to this PR next week.

maelle avatar Mar 12 '24 15:03 maelle

  • I added the lifecycle infrastructure. Does this seem correct @krlmlr?
  • I added test cases. Do they make any sense @szhorvat? If so it would make sense to add the same test cases as examples especially for graph_center() that currently has no example.

maelle avatar Mar 18 '24 14:03 maelle

  • I added test cases. Do they make any sense @szhorvat? If so it would make sense to add the same test cases as examples especially for graph_center() that currently has no example.

I had a very quick look, seems fine as a smoke test, and yes, the test you added for graph_center() would actually make a very good example (perhaps with a smaller tree).

szhorvat avatar Mar 19 '24 14:03 szhorvat

@szhorvat could you please fix the conflicts in src/cpp11.cpp, or tell me how to fix them? Thank you!

maelle avatar Mar 22 '24 10:03 maelle

cpp11::cpp_register()

krlmlr avatar Mar 22 '24 16:03 krlmlr

Needs the decor package.

krlmlr avatar Mar 22 '24 16:03 krlmlr

I merged main into this branch and fixed the conflict by regenerating this file using R -q -e 'cpp11::cpp_register()'

Does this mess up Aviator because it won't be able to rebase anymore?

szhorvat avatar Mar 22 '24 16:03 szhorvat

Aviator might be fine, I can't identify the reason why it sometimes fails to rebase.

krlmlr avatar Mar 22 '24 17:03 krlmlr

thanks both!

maelle avatar Mar 25 '24 13:03 maelle

This pull request failed to merge: PR cannot be automatically rebased, please rebase manually to continue. Remove the blocked label to re-queue.

Additional debug info: Failed to rebase this PR onto the latest changes from the base branch. You will probably need to rebase this PR manually and resolve conflicts).

aviator-app[bot] avatar Mar 25 '24 13:03 aviator-app[bot]