2

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?

Michael Bishop
  • 1,875
  • 4
  • 17
  • 23

1 Answers1

2

I would start with the following approach:

  1. Read the whole file using readLines().
  2. Drop the comment lines, lines that start with '%'.
  3. Cut the lines into pieces, lines that start with a star ('*') mark the start of a new piece.
  4. 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.

Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53