The "edgelist" format is always numeric, so it does not use vertex names. If you want to keep the names use another format, e.g. ncol
:
g <- graph.formula(a-b-c)
write.graph(g, format="ncol", file="test.ncol")
g2 <- read.graph("test.ncol", format="ncol")
str(g2)
# IGRAPH UN-- 3 2 --
# + attr: name (v/c)
# + edges (vertex names):
# [1] a--b b--c
Btw. when you do
V(graph)$name <- V(graph)
that is not the best, because many igraph functions assume that vertex names are characters, and V(graph)
is numeric. So do
V(graph)$name <- as.character(V(graph))
instead.