Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ vertex.attributes <- function(graph, index = V(graph)) {

if (!missing(index)) {
index_is_natural_sequence <- (length(index) == vcount(graph) &&
identical(index, seq(1, vcount(graph))))
identical(index, V(graph)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think this should be

Suggested change
identical(index, V(graph)))
identical(index, as.numeric(seq_len(vcount(graph)))))

We want to cater for cases where !missing(index) but index is still essentially V(g) . I see:

library(igraph)
g <- make_ring(10)

identical(V(g), V(g))
#> [1] FALSE

Created on 2024-07-18 with reprex v2.1.0

Similarly to #1432 (comment).

Copy link
Contributor

Choose a reason for hiding this comment

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

graph <- make_ring(5)
index <- V(graph)
identical(index, as.numeric(seq_len(vcount(graph))))
# returns FALSE.

Try all(index == V(graph))

Copy link
Contributor

Choose a reason for hiding this comment

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

@clpippel: all() is challenging if the vectors are of different length? We'd still want to check the lengths first.

Would the all() route be faster?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we also want to check isTRUE(attr(g, "is_all")) ?

options(conflicts.policy = list(warn = FALSE))

library(igraph)
g <- make_ring(10)
dput(V(g))
#> structure(1:10, class = "igraph.vs", is_all = TRUE, env = <weak reference>, graph = "516d6a01-f041-48ae-bbe3-60dd751a8f4b")

Created on 2024-08-22 with reprex v2.1.0

Need to check if this other code path is ever touched -- easiest way by breaking it and running tests or revdeps.

if (!index_is_natural_sequence) {
for (i in seq_along(res)) {
res[[i]] <- res[[i]][index]
Expand Down