From murdoch at stats.uwo.ca  Sat Apr 26 03:19:25 2008
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Fri, 25 Apr 2008 21:19:25 -0400
Subject: [Rd] returning vectors of unknown size from C (with .C)
In-Reply-To: <624934630804251723n2e6b6345gc1678297e9412d34@mail.gmail.com>
References: <624934630804251723n2e6b6345gc1678297e9412d34@mail.gmail.com>
Message-ID: <4812831D.5070100@stats.uwo.ca>

Ramon Diaz-Uriarte wrote:
> Dear All,
>
> In a package, I am using ".C" to call some C functions. In one case,
> the number of elements of the return vectors are not known in R before
> the C call. (Two of the vectors are integers, the third is vector of
> character strings).
>
> Passing from R a vector of the maximum possible size would be a huge
> waste. I understand one alternative is to use ".Call", but I'd rather
> avoid it if I can (all of the code seems working except for the return
> of values into R). Another would be to write to a file from C and then
> read that into R, but this looks very ugly. Are there any other
> reasonable alternatives, or should I just use .Call?
>   

.Call is usually easiest, but another possibility is to have two entry 
points:  one to calculate how much space you need, a second to pass in a 
vector that's the right size to hold the result.

Duncan Murdoch
> Thanks,
>
> R.
>
>
>
>



[Rd] returning vectors of unknown size from C (with .C)
Duncan Murdoch