This tutorial and the package documentation describe how to do it for pajek files of the .net format, but I need to import .paj files. I don't expect there is code that will import all .paj files, but perhaps someone has code that will work for some simpler ones that I could then modify for my purposes?
1 Answers
I would start with the following approach:
- Read the whole file using
readLines()
. - Drop the comment lines, lines that start with '
%
'. - Cut the lines into pieces, lines that start with a star ('
*
') mark the start of a new piece. - Inspect each piece in the order they appear and convert them into the appropriate R data structure.
In Step 4 you may have several types of pieces:
*Network
is the start of a network.*Vertices
defines vertices and belongs to the previous network.*Edges
defines undirected edges, it belongs to the previous network.*Arcs
defines directed edges, it belongs to the previous network.*Partition
is the start of a partition.*Vector
is the start of a vector.
For converting a *Network
piece into an igraph graph, glue it together with the *Vertices
, *Edges
and/or *Arcs
pieces that come right after it, and then call read.graph(..., format="pajek")
via a textConnection()
. This way you don't need to create temporary files.
The *Partition
and *Vector
pieces are simple, just convert them to R vectors, using scan()
and textConnection()
.
I haven't tried all this, but I think it is not too difficult and should work fine. Tell me if you have any difficulties.
Also, Pajek file formats are poorly documented, so I might be wrong, there might be other piece types, etc.
You may also consider adding a bug report at the igraph bug tracker to request this feature.

- 10,705
- 1
- 36
- 53
-
I have submitted a bug report for this: https://bugs.launchpad.net/igraph/+bug/1046133 – Gabor Csardi Sep 05 '12 at 02:55