-
-
Notifications
You must be signed in to change notification settings - Fork 208
feat: Add attribute combination support to graph operators #2676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
c75e174
41c4b0c
5f7521a
cb49b91
d7e8bdc
c26ab02
f9ad5b3
b58da44
04ab715
6d94668
5bebc2e
05336ba
a85a78c
d1ac089
96e21e2
874f8eb
eb89372
fde3bed
fbf2bcc
9a635d7
409b310
a8987c4
a190d59
757f82d
69bd17e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1290,7 +1290,7 @@ is_bipartite <- function(graph) { | |
|
|
||
| ############# | ||
|
|
||
| igraph.i.attribute.combination <- function(comb) { | ||
| igraph.i.attribute.combination <- function(comb, allow_rename = FALSE) { | ||
| if (is.function(comb)) { | ||
| comb <- list(comb) | ||
| } | ||
|
|
@@ -1310,34 +1310,40 @@ igraph.i.attribute.combination <- function(comb) { | |
| if (anyDuplicated(names(comb)) > 0) { | ||
| cli::cli_warn("Some attributes are duplicated") | ||
| } | ||
| known_names <- c( | ||
| "ignore", | ||
|
schochastics marked this conversation as resolved.
Outdated
|
||
| "sum", | ||
| "prod", | ||
| "min", | ||
| "max", | ||
| "random", | ||
| "first", | ||
| "last", | ||
| "mean", | ||
| "median", | ||
| "concat" | ||
| ) | ||
| known_codes <- c(0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) | ||
|
schochastics marked this conversation as resolved.
Outdated
|
||
| if (allow_rename) { | ||
| known_names <- c(known_names, "rename") | ||
| known_codes <- c(known_codes, NA_integer_) | ||
| } | ||
| comb <- lapply(comb, function(x) { | ||
| if (!is.character(x)) { | ||
| x | ||
| } else { | ||
| known <- data.frame( | ||
| n = c( | ||
| "ignore", | ||
| "sum", | ||
| "prod", | ||
| "min", | ||
| "max", | ||
| "random", | ||
| "first", | ||
| "last", | ||
| "mean", | ||
| "median", | ||
| "concat" | ||
| ), | ||
| i = c(0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), | ||
| stringsAsFactors = FALSE | ||
| ) | ||
| x <- pmatch(tolower(x), known[, 1]) | ||
| if (is.na(x)) { | ||
| idx <- pmatch(tolower(x), known_names) | ||
| if (is.na(idx)) { | ||
| if (!allow_rename && identical(tolower(x), "rename")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be more logical to me to invert the two if (identical(tolower(x), "rename") && !allow_rename) {
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why identical btw?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you seem to hold a grudge against |
||
| cli::cli_abort( | ||
| "{.val rename} is only supported by graph operators ({.fn union}, {.fn intersection}, {.fn compose}, {.fn disjoint_union}), not by this function." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rephrase to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets surprisingly complicated so I would opt out of that and keep it as is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not Can't use rename with this function (not naming it) |
||
| ) | ||
| } | ||
| cli::cli_abort( | ||
| "Unknown/unambigous attribute combination specification." | ||
| ) | ||
| } | ||
| known[, 2][x] | ||
| if (is.na(known_codes[idx])) "rename" else known_codes[idx] | ||
| } | ||
| }) | ||
|
|
||
|
|
@@ -1435,6 +1441,15 @@ igraph.i.attribute.combination <- function(comb) { | |
| #' Concatenate the attributes, using the [c()] function. | ||
| #' This results almost always a complex attribute. | ||
| #' } | ||
| #' \item{"rename"}{ | ||
| #' Keep clashing attributes side-by-side under disambiguated names by | ||
| #' appending `_1`, `_2`, ... suffixes. This is the default for the | ||
|
schochastics marked this conversation as resolved.
Outdated
|
||
| #' graph operators [union()], [intersection()], [compose()] and | ||
| #' [disjoint_union()] and preserves their historical behaviour. | ||
| #' Only those operators accept `"rename"`; [simplify()] and | ||
| #' [contract()] will reject it because the rename strategy has no | ||
|
schochastics marked this conversation as resolved.
|
||
| #' per-element interpretation when many input values collapse into one. | ||
| #' } | ||
| #' } | ||
| #' @author Gabor Csardi \email{csardi.gabor@@gmail.com} | ||
| #' @seealso [graph_attr()], [vertex_attr()], | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.