Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Mathematica has lots of functions for working with graphs and networks, but there are still some functionality holes that are provided by other packages. Also, due to the nature of graph theory, often it is very hard (in practice impossible) to verify results returned by Mathematica without having an alternative implementation.

For these reasons it would be very useful to have access to another graph analysis library. igraph is one of the most mature open source network analysis packages. How can we access it from Mathematica?

share|improve this question

2 Answers 2

I wrote a small package for this. The main reason why I'm posting it here is to get some feedback on how to improve it. I'm new both R and RLink.

You can get the package here. Please see the installation instructions in, especially if you're a Mac user (important!).

How does it work?

RLink does not play well with igraph objects, so an edge-list representation is used to transfer data between R and Mathematica. Using a simple edge-list is good for performance and transparency too. On the R side, edge lists are marked with the mmaDirectedGraph attribtue. On the Mathematica side, Graph objects are auto-converted to R edge lists using RLink's RDataTypeRegister mechanism.

The function to be called and the argument list are passed separately to R. On the R side a function takes care of converting the egde lists to proper igraph objects, and then calls the function. If the return value is a graph, it also converts that back to an edge list.

Usage examples

Mac users will need to load RLink like this first (again, follow the instructions on github!!):

<< RLink`


InstallR["RHomeLocation" -> 

Note: if using Mathematica 10.0.1, also specify the R version, e.g.

InstallR["RHomeLocation" -> 
  "/Library/Frameworks/R.Framework/Resources", "RVersion" -> "3.1"]



(* ==> {2.} *)


enter image description here

share|improve this answer
Very cool! One suggestiong would be that if you want to transfer meta-data as well, then use the and functions to convert between igraph objects and simple tables (one for the vertices, one for edges). – Gabor Csardi May 3 '13 at 17:36
@Gabor Thanks for the suggestion! I'm not yet experienced with either igraph or R, so any advice is most welcome. – Szabolcs May 3 '13 at 17:38
Thanks to Leonid for showing me how to use an external R installation on Mac! – Szabolcs May 23 '13 at 4:25
up vote 7 down vote accepted

To overcome some limitations of RLink with regard to performance and parallelizability, I also created a LibraryLink based interface to igraph:

It does does not have full coverage of igraph functions, but it does provide much of the functionality that is not in Mathematica, in particular:

  • Centrality measures for weighted graphs
  • Edge and vertex coloured graph isomorphism, multigraph isomorphism
  • Subgraph isomorphism
  • Network motif finder
  • Community detection algorithms with better control
  • More layout algorithms
  • Many other things such as all cliques, minimum feedback arc set, graphlet decomposition, rewiring, degree sequence graphicality testing, and alternative algorithms for several things already in Mathematica, etc.

The package is available for 64-bit Windows, OS X and Linux.

I recommend using IGraph/M instead of IGraphR if the functionality you need is already included. It is faster and more robust than IGraphR.

After installing the package, load it as


and open he documentation notebook with


It contains many examples.

enter image description here

I am hoping that eventually IGraph/M will become a community project. Contributions of all kinds are welcome: comments/suggestions on features & the API, editing usage message and documentation, adding more cool examples, converting the documentation to a format compatible with the Documentation Centre, implementing new functionality, etc.

share|improve this answer
I played around a few functions in IGraphM. I notice that most functions for graph isomorphism don't support digraphs. But they support digraphs in the original igraph C library. Is it possible to make those functions compatible with digraphs? – Han Xiao Nov 15 at 9:02
@HanXiao What are you referring to precisely? The current version of IGraph/M has better support for directed graphs than the released version of igraph (0.7.1). Each isomorphism function supports directed graphs. In igraph 0.7.1, Bliss doesn't. I submitted a patch to igraph which updates Bliss to the latest version exactly to support directed ones. There was a confusion with LAD and if you use it on directed graphs, will will give a warning. This is a bug (already fixed in the development version), and the warning can be ignored. LAD supports directed ones too. – Szabolcs Nov 15 at 11:30
Thanks for the clarification. I have to admit that I only tested functions using LAD. The warning did confuse me. And I didn't find any demonstrations on digraphs. But now my questions are solved. I'm thinking of using some functions from IGraphM to speed up my code. Really appreciate your work on this package. – Han Xiao Nov 15 at 12:41
@HanXiao All suggestions, comments, etc. are welcome! Feel free to write me an email. Even if you just tell me which functions you use from the package, that will be useful. – Szabolcs Nov 16 at 8:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.