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, but this functionality is not yet as mature as the igraph library. It is useful to have access to igraph from Mathematica, both for accessing functionality that Mathematica does not have and for verification. Calling igraph through its C interface is possible, but not convenient.

How can we use RLink to call it more conveniently?

share|improve this question

1 Answer 1

up vote 18 down vote accepted

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

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.