[Rd] .Call - applying setAttrib(x, R_DimSymbol, s) to a matrix being an element of a list

From: Oleg Sklyar <osklyar_at_ebi.ac.uk>
Date: Wed 16 Mar 2005 - 17:40:54 GMT


Dear R developers,

I am writing some C code that loads multiple images into a list of R matrices. The whole R object is created within the C code. To simplify coding, elements of the list are first created as vectors and then converted to corresponding matrices using setAttrib(x, R_DimSymbol, s). Generally the code works fine except for one detail. Applying setAttrib sets ALL elements (matrices) in the list to the same size, namely to the one last applied, doesn't matter if other matrices are larger or smaller. The command is applied to an element, not to the whole list in the following way, see below. Is there any way to change the dims of an element without altering other elements in this example? Furthermore, if I skip the last command and return a list of vectors instead of a list of matrices - all vectors have different lengths corresponding to the respective image sizes.

// creating the list to hold matrices

SEXP result = allocVector(VECSXP, nFiles);

// creating a vector for the list element i
SET_VECTOR_ELT(result, i, allocVector(INTSXP, size[0] * size[1]));

// getting a pointer to the element to simlify coding
SEXP element = VECTOR_ELT(result, i);

// writing some values to the element

// converting element into a matrix

setAttrib(element, R_DimSymbol, imgSize);

Thanks in advance for help
Oleg

Dr Oleg Sklyar
European Bioinformatics Institute
Wellcome Trust Genome Campus
Hinxton, Cambridge, CB10 1SD
England
phone/fax +44(0)1223 49 4478/4468
e-mail osklyar@ebi.ac.uk



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Mar 17 04:43:21 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:02 GMT