[Rd] .Call - applying setAttrib(x, R_DimSymbol,
s) to a matrix being an element of a list
Oleg Sklyar
osklyar at ebi.ac.uk
Wed Mar 16 18:40:54 CET 2005
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 at ebi.ac.uk
More information about the R-devel
mailing list