I can reproduce this. This is what I get:
cat(file = tmp <- tempfile(),
"a b 1
a b 2
b a 3
a a 4
a a 2
")
g <- read.graph(tmp, format = 'ncol', directed = TRUE)
g2 <- as.undirected(g, mode = "collapse")
get.data.frame(g2)
# from to weight
# 1 a a 7
# 2 a b 5
igraph.version()
# [1] "0.7.1"
So it seems that it is indeed a bug. Please report it at https://github.com/igraph/igraph. Thanks.
It seems that as.undirected()
has problems with multiple edges. This is a workaround:
# g3 <- as.undirected(simplify(g, remove.loops = FALSE))
# get.data.frame(g3)
# from to weight
# 1 a a 6
# 2 a b 6