[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] How to pass graphs from R to C extensions? .C or .Call ?

From: Gábor Csárdi
Subject: Re: [igraph] How to pass graphs from R to C extensions? .C or .Call ?
Date: Mon, 29 Jun 2009 08:18:53 +0200


while theoretically it is possible to use the .C interface to pass
igraph graphs to C code, in practice it is not. You need to use the
.Call interface.

There are plenty of examples on how to do this in the igraph source
code. Check Rinterface.c, that contains the glue functions between R
and the C library. The C code for the function itself should not
contain any R-specific code.


On Sun, Jun 28, 2009 at 7:03 PM, Aaron McDaid<address@hidden> wrote:
> Hi,
> I hope you can spare a few minutes to help me with this. I'm trying to
> use the .C interface in R to access simple properties such as the
> vcount of a graph. This is just a toy exercise at first. The .Call
> interface looks a little complicated and risky; is it possible to
> efficiently access graphs using R's   .C interface? Or will I have to
> use .Call and SEXPs, as per
> http://lists.gnu.org/archive/html/igraph-help/2007-08/msg00007.html ?
> What types should I have in my C code? I've tried   const igraph_t
> **graph  also, without success? And am I using the correct parameters
> to the .C function in R?
> Here's my C code:
>  void vertices_count(const igraph_t *graph, int *n) {
>        Rprintf("graph: %p\n", graph);
>        Rprintf("graph: %p\n", *graph);
>        igraph_integer_t vc = igraph_vcount(graph);
>        int vci = vc;
>        Rprintf("vcount: %ld\n", vci);
>        Rprintf("vcount: %ld\n", graph->n);
>        *n=9;
>  }
> And what happens in R:
>> library(igraph)
>> dyn.load("R/myRextension.so"); .C ("vertices_count", raf, as.integer(0))[[2]]
> graph: 0x156f0a8
> graph: 0x14a1128
> vcount: 0
> vcount: 21631272
> [1] 9
> As you can see, I'm able to call a simple function and return a simple
> dummy answer (9). However, my C code is unable to get the vertex count
> of the graph (which is 91707 by the way).
> - Mac OS X 10.5.7 on an iMac.
> - R version 2.9.0 (2009-04-17)
> - igraph 0.5.2
> Background:
> I'm hoping to write some C extensions to igraph in R (perhaps for
> inclusion in igraph proper in future), such as new community finding
> algorithms, as part of my PhD. I'll be developing them mostly in R
> itself initially, but would like to make fast C/C++ implementations
> available in R, when appropriate.
> Thanks,
> Aaron McDaid
> PhD student, just started in UCD, Dublin
> http://www.cliquecluster.org/
> www.aaronmcdaid.com
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help

Gabor Csardi <address@hidden>     UNIL DGM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]