Skip to content
Prev 68704 / 398506 Next

Advice for calling a C function

Thank you. I can't believe how much time I spent going over that short 
bit of code without noticing that I had switched the dimensions. I was 
sure there was some arcane bit of pointer-lore that was eluding me. 
Patrick Burns pointed out an alternative approach to me, leaving the 
data in the form of a double vector. The index in the double vector 
corresponding to the matrix location can be calculated from:

Rmatrix [row,col] is equivalent to: Cvector [(row-1) + 
(col-1)*nrows(Rmatrix)]

This is easily inserted inside a for loop, sidestepping the whole issue 
of rebuilding a matrix. This has the added bonus that I don't have to 
break the matrix back down into a vector to pass it back to R.

Thank you all for your very helpful advice. Since most of this 
discussion has been in the R-help list, that's where I sent this post. 
In future I'll direct my C questions to the devel list. Hopefully, any 
further questions I have won't involve anything so silly as switching 
indexes.

Cheers,

Tyler

Tyler Smith

PhD Candidate
Department of Plant Science
McGill University
21,111 Lakeshore Road
Ste. Anne de Bellevue, Quebec
H9X 3V9
CANADA

Tel: 514 398-7851 ext. 8726
Fax: 514 398-7897

tyler.smith at mail.mcgill.ca
Huntsinger, Reid wrote: