title: Lemon Graph Library on R using Rcpp
body: <p>I think that this answer is a bit complex because it involves several things.</p>
  
  <p>I want to do high performance computations with R particularly with graphs (networks). As a R package <strong>igraph</strong> is very nice. But R is slow, so I want to code the computationally expensive routines in C++ (maybe in C). I take a look at the <strong>igraph</strong> C library and I found it a little messy to work with. I also look at the <strong>Boost Graph Library</strong> and I read about it that it is difficult to learn. So I eventually found <a href="http://lemon.cs.elte.hu/trac/lemon" rel="nofollow">Lemon Graph Library</a>. It is in C++ and seems very nice to work with.</p>
  
  <p>So I installed the Lemon Graph Library as recommended in the official page. Then using the <strong>Rcpp</strong> and <strong>inline</strong> packages I manage myself to run Lemon Graph C++ code from R. <a href="http://deliriosderayohauno.blogspot.com/2011/02/lemon-graph-library-lgl-instalation.html" rel="nofollow">Here</a> I write in detail what I had made. But basically I put this:</p>
  
  <pre><code>   inc &lt;- '
             #include &lt;lemon/list_graph.h&gt;
             using namespace lemon ;
             '
  
  
     src &lt;- '
            int xx = Rcpp::as&lt;int&gt;(x);
  
            int res = xx + 1;
  
            ListDigraph g;
  
            ListDigraph::Node u = g.addNode();
            ListDigraph::Node v = g.addNode();
            ListDigraph::Arc  a = g.addArc(u, v);
  
            int i = countNodes(g);
            int j = countArcs(g);
  
            Rprintf("num nodes is %d , and num edges is %d \\n",i,j);
  
            return Rcpp::wrap(res);
            '
  
         fun &lt;- cxxfunction( signature(x="numeric"), body=src,include=inc, plugin="Rcpp")
  </code></pre>
  
  <p>in a myexample_inline.R file and then run a R console and write:</p>
  
  <pre><code>&gt; library("inline")
  &gt; library("Rcpp")
  &gt; source("myexample_inline.R")
  &gt; fun(1)
  num nodes is 2 , and num edges is 1 
  [1] 2
  </code></pre>
  
  <p>So it works !!! But now I have the following problem. If I make a C++ function (say double func1(g)) that for example calculates some property to some Lemon graph object. How I call that function from the inlined code? I must made func1() as a template function and put it in the include field of cxxfunction()?</p>
  
  <p>Basically: I can't figure out how to call a C++ function inlined in R from another C++ function also inlined in R. Is it possible? Is there another way that do not uses inline code?</p>
  
  <p>Maybe I can do it using <strong>Rcpp modules</strong> but I couldn't (still) figure out how to do this.
  I'm  having problems with making modules work. I will keep trying with this, but maybe I can get some kind of hint from here.</p>
  
  <p>I also thought about the possibility to develop (my first) a package. But I had the problem that the Lemon Graph C++ code call the headers in this way (for example):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;lemon/list_graph.h&gt;
  </code></pre>
  
  <p>So it means (at least I believe this) that I can not avoid the installation of the Lemon Graph Library. If I want to make a R package of the Lemon Graph Library I have to "rewrite" all the code again !!! So this is not my main option.</p>
  
  <p>Best Regards</p>