Skip to content

Commit

Permalink
refactor: less if else in vertex_attr() (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviator-app[bot] authored Mar 26, 2024
2 parents 7bebe49 + 3ebf64b commit 9f91693
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -380,20 +380,18 @@ vertex_attr <- function(graph, name, index = V(graph)) {
ensure_igraph(graph)
if (missing(name)) {
if (missing(index)) {
vertex.attributes(graph)
} else {
vertex.attributes(graph, index = index)
}
} else {
myattr <-
.Call(R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_vertex)[[as.character(name)]]
if (is_complete_iterator(index)) {
myattr
} else {
index <- as_igraph_vs(graph, index)
myattr[index]
return(vertex.attributes(graph))
}
return(vertex.attributes(graph, index = index))
}
myattr <-
.Call(R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_vertex)[[as.character(name)]]
if (is_complete_iterator(index)) {
return(myattr)
}
index <- as_igraph_vs(graph, index)
myattr[index]

}

#' Set one or more vertex attributes
Expand Down

0 comments on commit 9f91693

Please sign in to comment.