I think this answer is a bit complicated because it includes a few things.
I want to do high performance computing with R, especially with graphs (networks). As a package, R igraph is very nice. But R is slow, so I want to code computationally expensive routines in C ++ (possibly C). I look at the igraph C library and I found it a little dirty for work. I also look at the Boost Graph Library , and I read about it that it is hard to learn. So in the end I found the Limographic Library . It is in C ++ and it is very pleasant to work with it.
So, I installed the Lemon Graph library, as recommended on the official page. Then, using the Rcpp and inline packages , I control myself to run Lemon Graph C ++ code from R. Here I write in detail what I did. But basically I said this:
inc <- '
#include <lemon/list_graph.h>
using namespace lemon ;
'
src <- '
int xx = Rcpp::as<int>(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 <- cxxfunction( signature(x="numeric"), body=src,include=inc, plugin="Rcpp")
in the myexample_inline.R file, and then start the R console and write:
> library("inline")
> library("Rcpp")
> source("myexample_inline.R")
> fun(1)
num nodes is 2 , and num edges is 1
[1] 2
So it works !!! But now I have the following problem. If I create a C ++ function (say, double func1 (g)), which, for example, calculates some property for some Lemon graph object. How do I call this function from inline code? Should I create func1 () as a template function and put it in the include cxxfunction () field?
: , ++, R, ++, R. ? , ?
, Rcpp, (-) , .
. , , , - .
( ) . , Lemon Graph ++ ():
#include <iostream>
#include <lemon/list_graph.h>
, ( , , ), Lemon Graph. R- Lemon Graph, "" !!! .