[Rd] .C returned array has odd results
murdoch.duncan at gmail.com
Fri Jan 27 21:29:07 CET 2012
On 27/01/2012 2:46 PM, Jonathan Lisic wrote:
> Hi, I'm sure this is a fairly simple problem, but I can't seem to find any
> specific information in the documentation as to what is going on. I am
> writing a simple nearest neighbor program that takes in a set of of points
> on a plane and returns the neighbors of those points, for a fixed number of
> neighbors. However, the returned integer array that is allocated in R
> seems to occasionally return incorrect results.
> I thought this would be because of GC, but I thought this was only for
> SEXPs, or at least this is the impression I got from reading the
> documentation. So is there some obvious reason why my results seem to get
> mangled by this call? I have checked my program through several thousand
> loops in C, and always get the same results, so I assume that this is
> something I'm doing wrong in R.
You don't show us what your incorrect results are. The most likely
causes are on the C side, and besides just doing the wrong calculation,
I'd be suspicious of out of bounds writes to arrays. Do you treat any
of the other arguments besides the 5th one as arrays? Are you sure the
length of array passed in is long enough? Do you have local allocations
of arrays, and are they long enough? Do your type declarations in C
match the four double* declarations followed by six int* declarations
implied by your .C call?
> Here is the code for my .C call. I could post the C code if someone thinks
> it's important, but I'm just changing the values of integer array specified
> in R.
> [[alternative HTML version deleted]]
> R-devel at r-project.org mailing list
More information about the R-devel