"as_incidence_matrix" not working as intended

I am using the following code to convert a graph into its Adjacency and Incidence matrix formats;

library(igraph)
library(network)
library(intergraph)
library(Matrix)

df <- read.table(textConnection("
To          From
A          D       
B          A       
C          A       
D          C       
D          D
D          B
E          B
E          D"),
                 header=T, stringsAsFactors=F)

df <- df[,c(2,1)]
df <- df[order(df$From),]

g <- graph.data.frame(df[,1:2], directed = T)
V(g)$type <- V(g)$name %in% df[,1]


adj <- as_adjacency_matrix(g, sparse = F)
adj

set.seed(9)
plot(g)

g

inc <- as_incidence_matrix(g)
inc

The output is not printed and kills the R session.

I cannot reproduce this on my machine (Apple Silicon, macOS 12.0.1, R 1.4.2, igraph 1.2.9, installed from CRAN). Please provide more details, especially the version numbers of your OS, R itself, igraph, and the OS that you are using.

I cannot reproduce it if I evaluate lines one by one. I can sometimes reproduce it if I paste the whole thing at once (without the irrelevant packages, namely network and intergraph). It would be nice if the example could be further minimized.

I’m on macOS 10.14, Intel, igraph 1.2.9.

@shreyaskhadse If you can reproduce this consistently, can you please construct a truly minimal example? Try to remove lines one by one and keep only what’s absolutely necessary for the crash. If possible, please construct the graph on a single line in terms of vertex indices (not vertex names), and do not modify it further.

It seems like you are hitting a bug in the core C igraph library that was fixed in version 0.9.3; the problem is that your graph is not fully bipartite (there are edges within the partitions). Unfortunately the R interface is still based on version 0.8.x of the C core; we are working hard to bring it up-to-date with the C core (see the dev-1.3 branch in GitHub - igraph/rigraph: igraph R package), but it will take a few weeks at least until we can release a version that is based on an up-to-date version of the C core.

If you need to make this work, the workaround for the R interface is to remove all edges that go between vertices of the same type.

1 Like