Update: I am no longer maintaining IGraphR. I recommend that you transition to IGraph/M instead. If you need a feature that IGraph/M does not yet have, please submit a feature request.
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 README.md, 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`
SetEnvironment[
"DYLD_LIBRARY_PATH" ->
"/Library/Frameworks/R.Framework/Resources/lib"];
InstallR["RHomeLocation" ->
"/Library/Frameworks/R.Framework/Resources"]
Note: if using Mathematica 10.0.1, also specify the R version, e.g.
InstallR["RHomeLocation" ->
"/Library/Frameworks/R.Framework/Resources", "RVersion" -> "3.1"]
Examples:
IGraph["vertex.connectivity"][CycleGraph[5]]
(* ==> {2.} *)
IGraph["barabasi.game"][50]
