From tplate at blackmesacapital.com  Thu Jun 17 18:38:33 2004
From: tplate at blackmesacapital.com (Tony Plate)
Date: Thu Jun 17 18:38:49 2004
Subject: [Rd] using "= matrix (...)" in .C calls
In-Reply-To: <OFA53FF1DF.EBC14134-ON85256EB6.0052F4B7-85256EB6.00569613@
	EU.novartis.net>
References: <OFA53FF1DF.EBC14134-ON85256EB6.0052F4B7-85256EB6.00569613@EU.novartis.net>
Message-ID: <6.1.0.6.2.20040617103352.0cf67ec0@mailhost.blackmesacapital.com>

Try looking at subsection "4.2 Interface functions .C and .Fortran" in the 
manual "Writing R Extensions".  (hint: it's done in a simple way that 
should be obvious after you've read this.)  You're far more likely to get a 
helpful answer if you indicate in your posting that you've read this and 
indicate how it did not answer the questions you have.  Also, this type of 
basic question is more appropriate for R-help, not R-devel.

hope this helps,

Tony Plate


At Thursday 09:43 AM 6/17/2004, you wrote:
>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(nobs),
>                        as.integer(nsplit),
>                        as.integer(nodes),
>                        as.integer(ncat),
>                        as.integer(cats *!isord),
>                        as.integer(max(cats)),
>                        as.integer(xval),
>                        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
>*ncat,
>               Sint *numcat,    Sint *maxcat,    Sint *xvals,     Sint
>*which,
>               double *cptable, double *dsplit,  Sint *isplit,    Sint
>*csplit,
>               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,
>
>Clayton
>
>         [[alternative HTML version deleted]]
>
>______________________________________________
>R-devel@stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-devel


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