set.seed(123)
g1 <- randomGraph(letters[1:10], 1:4, p=.3)
s1 <- graph2SparseM(g1, useweights=TRUE)
g2 <- sparseM2Graph(s1, letters[1:10], edgemode="undirected")
## consistency check
stopifnot(all.equal(g1, g2))
Run the code above in your browser using DataLab