[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] How to pass graphs from R to C extensions? .C or .Call ?
From: |
Aaron McDaid |
Subject: |
[igraph] How to pass graphs from R to C extensions? .C or .Call ? |
Date: |
Sun, 28 Jun 2009 18:03:45 +0100 |
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] How to pass graphs from R to C extensions? .C or .Call ?,
Aaron McDaid <=