Monday, September 10, 2012

igraph 0.6 issues: Changed numbering of Vertices

I have tried one of my previous scripts with an updated igraph version and I got an interesting (pretty much unexpected) error:

At type_indexededgelist.c:269 : invalid (odd) length of edges vector, Invalid edge vector

The problem is that it was a well-tested set of scripts (I am using the testthat package for a while) that was working perfectly before so I was a bit confused. The error message indicated that the issue was related to the igraph package. It took me a while but I found an interesting entry in the release notes of igraph v0.6:

Numbering from 1 in R

The biggest change in the R interface is that starting from this version vertices and edges are numbered from one. This change might be painful for many people, because it makes already existing code incompatible with igraph 0.6. To make the switch easier, there is now an igraph0 package on CRAN; igraph0 uses 0-based vertex and edge ids, and it can be used to run old code. Note, however, that igraph0 will not be developed in the future. Please use the igraph package for current and future work.

(Also note that in Python and C vertices and edges are still numbered from zero, as these languages traditionally use zero-based indexing.)


Cool :-) After my first frustation I can understand the reasons for such a change. Sometimes things like this are necessary in a project's life. It takes a while to adapt, but a few initial wrong decisions cannot be fixed easily. If they cause more trouble than how useful they are, time has come to eliminate them.


So the solution is to stick to the igraph0 package, or try to update the scripts to index from 1. Since my project is only required for my research I have chosen the second approach. For the time-critical tasks the answer would have been definitely the igraph0 package.

4 comments:

  1. Hey,

    I got a problem which same with, already updated the igraph to igraph0. But, it still having problem. You said to update the script to index from 1, but how? could you tell me where to change? thanks wanfahmi57[at]gmail.com


    ../fgclust4.4.r -i sampleReads_pairwise.txt -o sampleReads_clusters.txt -l -n 4858
    Error in add.edges(g, edges, attr = attrs) :
    At type_indexededgelist.c:269 : invalid (odd) length of edges vector, Invalid edge vector
    Calls: graph.data.frame2 -> add.edges -> .Call
    Execution halted

    ReplyDelete
    Replies
    1. Hi Wan,

      (Sorry for the late response, I haven't got any notification about your comment)

      There is two libraries now at the moment, igrap0 and igraph.

      The igraph0 package should work without any errors with your original script (if it doesn't, I'd suggest opening a new thread at the user mailing list, the developers are quite responsive).

      If you use however the standard igraph (v0.6+) package, then **you have to update all the indices in your code from 'i' to 'i+1'**.

      This is quite a PITA, but that's why the igraph0 package exists.

      Delete
    2. Hi Richard,

      Thank you for replying my msg. Actually, I just changed the igraph to igraph0 in my python script and it worked. Thank you

      Delete
    3. Hi Wan,

      Glad to hear it worked in the end. Good luck!

      Delete