Using write.graph in igraph to output .net file

I think what I am missing here is simple, but what is the syntax for adding arguments to the write.graph function in the R igraph package? I am trying to output a network to a pajek (.net) file with weighted edges and ids. I've tried the following commands but keep getting errors ("Unknown arguments for write.graph (Pajek format)".):

write.graph(weightedg,file="musGiant2012.net", format="pajek",'weight')
write.graph(weightedg,file="musGiant2012.net", format="pajek", id=TRUE)
write.graph(weightedg,file="musGiant2012.net", format="pajek", ("id"))

      

Plus many others. I'm sure I'm committing a simple syntax error, but can't find any guidance on how to fix it.

+3


source to share


1 answer


From the docs at http://igraph.org/r/doc/write.graph.html :

The Pajek format is a text file, see read.graph for details. The corresponding vertex and edge attributes are also written to the file. This format has no additional arguments.



And http://igraph.org/r/doc/read.graph.html shows boundary weights as well as vertex ids are supported. Therefore, if you have vertex IDs as a named attribute id

, and your weights as an attribute weight

, then you don't need an additional argument. For example.

library(igraph)
g <- graph.ring(5)
V(g)$id <- letters[1:5]
E(g)$weight <- runif(ecount(g))

tmp <- tempfile()
write.graph(g, file = tmp, format = "pajek")

cat(readLines(tmp), sep = "\n")

#> *Vertices 5
#> 1 "a"
#> 2 "b"
#> 3 "c"
#> 4 "d"
#> 5 "e"
#> *Edges
#> 1 2 0.054399197222665
#> 2 3 0.503386947326362
#> 3 4 0.373047293629497
#> 4 5 0.84542120853439
#> 1 5 0.610330935101956

      

+3


source







All Articles