[Rd] using "= matrix (...)" in .C calls

clayton.springer at pharma.novartis.com clayton.springer at pharma.novartis.com
Thu Jun 17 17:43:33 CEST 2004

Dear R-devel,

I am trying to alter rpart so that it makes additional calculations when 
growing the tree. 

In the "rpart.s" there is a call to the C routine:

     rp    <- .C("s_to_rp2",
                       as.integer(cats *!isord),
                       which = integer(nobs),
                       cptable = matrix(double(numcp*cpcol), nrow=cpcol),
                       dsplit =  matrix(double(1),  nsplit,3),
                       isplit =  matrix(integer(1), nsplit,3),
                       csplit =  catmat,
                       dnode  =  matrix(double(1),  nodes, 3+numresp),
                       inode  =  matrix(integer(1), nodes, 6),
                       PACKAGE = "rpart")

Which in communicates with the C code in  "s_to_rp.c"

void s_to_rp2(Sint *n,         Sint *nsplit,    Sint *nnode,     Sint 
              Sint *numcat,    Sint *maxcat,    Sint *xvals,     Sint 
              double *cptable, double *dsplit,  Sint *isplit,    Sint 
              double *dnode,   Sint *inode)

Apparently the lines like:

        dsplit =  matrix(double(1),  nsplit,3),

Cause C arrays to be pulled over into an R matrix. However I can't figure 
out the syntax from context nor can I find documentation.

I have an array which was created and exists in the "C" part of the code, 
but I can not figure out how to pull it over to the "R" side.

The array was ALLOCed as 1-D array (of size nodes * variables), and 
ultimately I would like to get into matrix of nodes * variables.

Any help or advice would be appreciated.

thanks in advance,

	[[alternative HTML version deleted]]

More information about the R-devel mailing list