From wdunlap at tibco.com  Wed Jun 19 17:41:39 2013
From: wdunlap at tibco.com (William Dunlap)
Date: Wed, 19 Jun 2013 15:41:39 +0000
Subject: [Rd] Calling an array in a struct in C to R
In-Reply-To: <1371651280258-4669884.post@n4.nabble.com>
References: <1371651280258-4669884.post@n4.nabble.com>
Message-ID: <E66794E69CFDE04D9A70842786030B931C30435C@PA-MBX01.na.tibco.com>

> should I rewrite my C code using Call in R?

Yes, rewrite it to use the .Call() interface.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf
> Of Tee-Jay-Ardie
> Sent: Wednesday, June 19, 2013 7:15 AM
> To: r-devel at r-project.org
> Subject: [Rd] Calling an array in a struct in C to R
> 
> Hi there,
> 
> Although I'm a quite experienced R user and know my ways in C, I stumbled
> upon a problem I don't know how to solve. Therefore, I hope someone can
> provide me with the information or pointers I need in order to understand
> the way in which the communication between R and C occurs. I have the
> following C code which basicallly reflects what I want:
> 
> typedef struct
> {
>        float *array;
>        size_t used;
>        size_t size;
> } Array;
> 
> void main2R()
> {
>       Array a;
>       examplefunction(&a);   /*fills and dynamically grows a->array*/
> }
> 
> Now I would want to return a.array or a->array to R. According to the R
> manuals, the compiled C code should not return anything except through its
> arguments. The problem here is, I have a dynamically growing array, and I
> have no idea what to pass on to C from R in order to let that work.
> The word 'should' indicates that the compiled code may return something in
> special circumstances, but I have no idea how to get a.array in R.
> 
> So my question is simply this: How on earth do I get the information in the
> float array 'a.array' in R? Is it even possible or should I rewrite my C
> code using Call in R?
> 
> Another, not preferred, options is to pre-allocate the array/vector in R on
> a fixed (large-enough) size? Or do I miss something here?
> 
> Regards.
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Calling-an-array-in-a-
> struct-in-C-to-R-tp4669884.html
> Sent from the R devel mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Calling an array in a struct in C to R
William Dunlap