From f480032eb5d414faf287e4300214fac43512cead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 26 Mar 2024 14:47:54 +0100 Subject: [PATCH 1/2] refactor: explaining variables --- R/attributes.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/R/attributes.R b/R/attributes.R index 77b4ad5b4a8..199aa43be2e 100644 --- a/R/attributes.R +++ b/R/attributes.R @@ -517,12 +517,16 @@ vertex.attributes <- function(graph, index = V(graph)) { res <- .Call(R_igraph_mybracket2_copy, graph, igraph_t_idx_attr, igraph_attr_idx_vertex) - if (!missing(index) && - (length(index) != vcount(graph) || any(index != V(graph)))) { - for (i in seq_along(res)) { - res[[i]] <- res[[i]][index] + if (!missing(index)) { + index_length_not_vertices_number <- (length(index) != vcount(graph)) + some_index_not_vertices <- (!all(index %in% V(graph))) + if (index_length_not_vertices_number || some_index_not_vertices) { + for (i in seq_along(res)) { + res[[i]] <- res[[i]][index] + } } } + res } From dad6e67366dbc9842305cc45b05e328953d33337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 8 Apr 2024 12:26:26 +0200 Subject: [PATCH 2/2] Update R/attributes.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kirill Müller --- R/attributes.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/attributes.R b/R/attributes.R index 199aa43be2e..88c84e040f1 100644 --- a/R/attributes.R +++ b/R/attributes.R @@ -518,9 +518,8 @@ vertex.attributes <- function(graph, index = V(graph)) { res <- .Call(R_igraph_mybracket2_copy, graph, igraph_t_idx_attr, igraph_attr_idx_vertex) if (!missing(index)) { - index_length_not_vertices_number <- (length(index) != vcount(graph)) - some_index_not_vertices <- (!all(index %in% V(graph))) - if (index_length_not_vertices_number || some_index_not_vertices) { + index_is_natural_sequence <- (length(index) == vcount(graph) && all(index == V(graph))) + if (!index_is_natural_sequence) { for (i in seq_along(res)) { res[[i]] <- res[[i]][index] }