Skip to content

feat!: Stop accepting setting layout as a graph attribute if it is a matrix #1303

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
33 changes: 33 additions & 0 deletions R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ graph_attr <- function(graph, name) {
set_graph_attr <- function(graph, name, value) {
ensure_igraph(graph)

# Code that accesses g$layout can stay for now, revisit in 2029.
# https://github.com/igraph/rigraph/issues/775
if (name == "layout" && is.matrix(value)) {
lifecycle::deprecate_stop(
"2.1.0",
"set_graph_attr(layout = 'matrix(...)')",
"set_vertex_attr(layout = )",
details = "Using a matrix for the `layout` attribute is deprecated.
Set the vertex attribute `layout` instead."
)
return(set_vertex_attr(graph, name, value))
}

.Call(R_igraph_mybracket3_set, graph, igraph_t_idx_attr, igraph_attr_idx_graph, name, value)
}

Expand Down Expand Up @@ -386,6 +399,8 @@ vertex_attr <- function(graph, name, index = V(graph)) {
} else {
vertex.attributes(graph, index = index)
}
} else if (name == "layout") {
...
} else {
myattr <-
.Call(R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_vertex)[[as.character(name)]]
Expand Down Expand Up @@ -465,6 +480,24 @@ i_set_vertex_attr <- function(graph, name, index = V(graph), value, check = TRUE
return(graph)
}

if (name == "layout") {
if (ncol(value) == 2) {
value <- list(x = value[, 1], y = value[, 2])
} else if (ncol(value) == 3) {
value <- list(x = value[, 1], y = value[, 2], z = value[, 3])
} else {
lifecycle::deprecate_stop("2.0.3", "set_graph_attr(layout = 'matrix(...)')", details = "Using a matrix for the `layout` attribute is defunct. Use vertex attributes `x`, `y` and `z` instead.")
}

iwalk(value, function(x, name) {
set_vertex_attr(graph, name, value = x, index = index, check = check)
})

return(graph)
}



# https://github.com/igraph/rigraph/issues/807
# Checks if any of those classes is inherited from
if (inherits(value, c("igraph.vs", "igraph.es"))) {
Expand Down