You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A tbl_graph can be created by providing two data frames, one for the nodes and one for the edges. However, when the edges data frame has a "sticky column" (meaning that this column is resilient to subsetting operations like select) this process fails.
Sticky columns are a thing for example in the sf package for spatial data, where the geometry column always remains after column subsetting. I know there are other packages using this logic as well, such as tsibble for time series data. Currently we cannot create tbl_graph objects directly from such data frames.
Error in graph_from_edgelist(as.matrix(edges[, 1:2]), directed = directed) :
graph_from_edgelist expects a matrix with two columns
The problem is in as.matrix(edges[, 1:2]), which in normal cases results in a two-column matrix, but when a sticky column is present it will become a three-column matrix because the sticky column is resilient to the subsetting operation.
A tbl_graph can be created by providing two data frames, one for the nodes and one for the edges. However, when the edges data frame has a "sticky column" (meaning that this column is resilient to subsetting operations like select) this process fails.
Sticky columns are a thing for example in the sf package for spatial data, where the geometry column always remains after column subsetting. I know there are other packages using this logic as well, such as tsibble for time series data. Currently we cannot create tbl_graph objects directly from such data frames.
The problem is in
as.matrix(edges[, 1:2])
, which in normal cases results in a two-column matrix, but when a sticky column is present it will become a three-column matrix because the sticky column is resilient to the subsetting operation.tidygraph/R/list.R
Line 89 in d88b167
An easy-fix would be to subset the matrix again, after subsetting the data frame:
This would cover all cases where a sticky column would be present and not harm regular cases. But maybe there are more elegant solutions.
The text was updated successfully, but these errors were encountered: