[R] accesing slots of S4 class in C code

From: Aniko Szabo <aniko.szabo_at_hci.utah.edu>
Date: Thu 18 Aug 2005 - 03:33:39 EST

I am trying to use a custom S4 object in my C code and I cannot get the access to its slots working.  

The following is a toy example, but even this crashes.  

In R I have:  

setClass("pd", representation(data="numeric"))

x <- new("pd", data=1:5)  

test <- function(pd.obj) {

  res <- .C("TestFun", pd.obj)



(Of couse I load the DLL as well.)  

The corresponding C file has:  

SEXP TestFun(SEXP pd_obj)


 SEXP t=R_NilValue;

 PROTECT(t = GET_SLOT(pd_obj, install("data")));

 UNPROTECT(1);  return(t);


What I hope to get as a result is the (1:5) vector.

In the long term, the vector will be a multi-dimensional array and I will want to do calculations using its contents in the C program.  

Thanks for any help,  


Huntsman Cancer Institute wishes to promote open communication while protecting confidential and/or privileged information. If you have received this message in error, please inform the sender and delete all copies.

        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Aug 18 03:37:37 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:50 EST