# [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(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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.76539207,"math_prob":0.97674346,"size":1615,"snap":"2023-14-2023-23","text_gpt3_token_len":485,"char_repetition_ratio":0.15270019,"word_repetition_ratio":0.0,"special_character_ratio":0.27925697,"punctuation_ratio":0.21428572,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9879237,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-29T04:49:32Z\",\"WARC-Record-ID\":\"<urn:uuid:3e9b3881-a5f0-4573-a4e0-b51713e45bce>\",\"Content-Length\":\"4534\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:336caf7f-840c-42e0-9092-c46a50e38c72>\",\"WARC-Concurrent-To\":\"<urn:uuid:c3250473-e18b-410e-be11-b9972ff62c4b>\",\"WARC-IP-Address\":\"129.132.119.195\",\"WARC-Target-URI\":\"https://www.stat.math.ethz.ch/pipermail/r-devel/2004-June/029891.html\",\"WARC-Payload-Digest\":\"sha1:BS4B26AOUJ7JNJVRSLWXIXLOSMLSMDLB\",\"WARC-Block-Digest\":\"sha1:VHFAMYAWURDNAGCDHX5UHUQ65LIA24HI\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296948932.75_warc_CC-MAIN-20230329023546-20230329053546-00364.warc.gz\"}"}