Skip to content
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

fix: g + vertices(1, 2, foo = 3) works again, regression introduced in igraph 2.0.0 #1247

Merged
merged 7 commits into from
Feb 13, 2024

Conversation

maelle
Copy link
Contributor

@maelle maelle commented Feb 12, 2024

Fix #1231

Partly refactoring for understanding for now.

Copy link
Contributor

aviator-app bot commented Feb 12, 2024

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 using Aviator.


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.

R/operators.R Outdated Show resolved Hide resolved
R/operators.R Outdated
names(e2)[wn] <- "name"
unnamed_elements_indices <- which(!rlang::have_name(e2))
if (length(unnamed_elements_indices) == 1) {
e2 <- rlang::set_names(e2[unnamed_elements_indices], "name")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the readability of this line is not obviously better but since I was using rlang above...

R/operators.R Outdated
} else if (is.null(names(e2))) {
## No names at all, everything is a vertex name
e2 <- list(name = unlist(e2, recursive = FALSE))
} else if (length(wn) == 0) {
} else if (length(unnamed_elements_indices) == 0) {
## If there are no non-named arguments, we are fine
} else {
## Otherwise, all unnamed arguments are collected and used as
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the case that was broken as far as I understand. Not sure why it works to fix it here.

}
la <- unique(sapply(e2, length))
res <- add_vertices(e1, la, attr = e2)
# When adding vertices via +, all unnamed arguments are interpreted as vertex names of the new vertices.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comes from the docs

@maelle
Copy link
Contributor Author

maelle commented Feb 12, 2024

library("igraph")
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#> 
#>     union

g <- make_empty_graph(1)
g
#> IGRAPH bd455eb D--- 1 0 -- 
#> + edges from bd455eb:
V(g)
#> + 1/1 vertex, from bd455eb:
#> [1] 1

g <- g +
  vertices("a", "b", foo = 5)
g
#> IGRAPH 34a9a54 DN-- 3 0 -- 
#> + attr: name (v/c), foo (v/n)
#> + edges from 34a9a54 (vertex names):
V(g)
#> + 3/3 vertices, named, from 34a9a54:
#> [1] <NA> a    b
V(g)$foo
#> [1] NA  5  5

Created on 2024-02-12 with reprex v2.1.0

@maelle maelle marked this pull request as ready for review February 12, 2024 14:45
}
la <- unique(sapply(e2, length))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this supposed to be nv? I think my change here is the fix.

@maelle maelle marked this pull request as draft February 12, 2024 14:54
@maelle maelle marked this pull request as ready for review February 12, 2024 15:09
@maelle maelle requested a review from krlmlr February 12, 2024 15:54
Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Since we obviously didn't have any tests, can you please add some?

expect_s3_class(V(g_all_unnamed), "igraph.vs")
expect_identical(V(g_all_unnamed)$name, c( NA, "a", "b"))

g_mix_named_unnamed <- g + vertices("a", "b", foo = 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with foo = 6:7 and foo = 8:10 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test. The error also happens with v1.6.0 and seems logical.

@maelle maelle marked this pull request as draft February 13, 2024 08:31
@maelle
Copy link
Contributor Author

maelle commented Feb 13, 2024

I added a test but I'm surprised I need to use unname(), is something wrong:

library("igraph")
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#> 
#>     union

g <- make_empty_graph(1)
g
#> IGRAPH ea2b4e5 D--- 1 0 -- 
#> + edges from ea2b4e5:
V(g)
#> + 1/1 vertex, from ea2b4e5:
#> [1] 1

g <- g +
  vertices("a", "b", foo = 5)
g
#> IGRAPH 6aaaab9 DN-- 3 0 -- 
#> + attr: name (v/c), foo (v/n)
#> + edges from 6aaaab9 (vertex names):
V(g)
#> + 3/3 vertices, named, from 6aaaab9:
#> [1] <NA> a    b
V(g)$name
#> <NA> <NA> <NA> 
#>   NA  "a"  "b"
V(g)$foo
#> [1] NA  5  5

Created on 2024-02-13 with reprex v2.1.0

And with v1.6.0, it's the same actually

library("igraph")
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#> 
#>     union

g <- make_empty_graph(1)
g
#> IGRAPH c331734 D--- 1 0 -- 
#> + edges from c331734:
V(g)
#> + 1/1 vertex, from c331734:
#> [1] 1

g <- g +
  vertices("a", "b", foo = 5)
g
#> IGRAPH dc14fb9 DN-- 3 0 -- 
#> + attr: name (v/c), foo (v/n)
#> + edges from dc14fb9 (vertex names):
V(g)
#> + 3/3 vertices, named, from dc14fb9:
#> [1] <NA> a    b
V(g)$name
#> <NA> <NA> <NA> 
#>   NA  "a"  "b"
V(g)$foo
#> [1] NA  5  5

Created on 2024-02-13 with reprex v2.1.0

We can discuss later today. 😸

@maelle maelle marked this pull request as ready for review February 13, 2024 08:39
@maelle maelle marked this pull request as draft February 13, 2024 08:39
@krlmlr krlmlr changed the title fix: make vertices(1, 2, foo = 3) work again fix: Adding vertices(1, 2, foo = 3) works again, regression introduced in igraph 2.0.0 Feb 13, 2024
@krlmlr krlmlr marked this pull request as ready for review February 13, 2024 14:27
@krlmlr krlmlr changed the title fix: Adding vertices(1, 2, foo = 3) works again, regression introduced in igraph 2.0.0 fix: g + vertices(1, 2, foo = 3) works again, regression introduced in igraph 2.0.0 Feb 13, 2024
@aviator-app aviator-app bot merged commit dfdc345 into main Feb 13, 2024
14 checks passed
@aviator-app aviator-app bot deleted the vertices branch February 13, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vertices(1, 2, foo = 3) no longer works
2 participants