Hi everyone,

I am currently trying to call some C code from R, specifically calling a
function which populates a C struct.

typedef struct{
   // contents
} Model;

void test(Model *m){
   // fill the struct with crap
}

I compile the C code into a shared library, which loads into R properly. My
simple test functions work (i.e adding numbers etc)
setModel <- function(){
   model<-vector("list", 6)
   name(model) <- c( SET THE NAMES OF THE MODEL HERE )
   model
}
t <- setModel()
testcode <- function(setModel){


dyn.load("Simulation.so")

foo <- .C("test", Model=setModel)
foo
}

testcode(t)

However I get segfaults whenever I try to access any of the variables
contained in Model. So my question is: am I doing something wrong here? Is
list the right data type to wrap a structure in? I cant see any
documentation about wrapping structs in R.

Also when I pass strings to C from R they dont seem to be passed at all? Is
this a problem with R or a problem with me and if so how do I fix it?



Many Thanks in advance,

Nathan

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to