diff --git a/R/attributes.R b/R/attributes.R index 7257215b53..2c24326e26 100644 --- a/R/attributes.R +++ b/R/attributes.R @@ -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) } @@ -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)]] @@ -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"))) {