[Rd] bypassing SET_DIM checking

miguel manese jjonphl at gmail.com
Sat Aug 12 15:36:31 CEST 2006


Hello,

I created an S3 "type" w/c is actually a list that should look like a
matrix but whose data is actually in an external file. The SEXP just
contains info on how to retrieve the data from the file. When I get to
the part of creating the SEXP, I found out that SET_DIM & SET_DIMNAME
checks the SEXP if the length matches (somewhere in src/main/attrib.c,
dimgets & dimnamegets IIRC (it's on my other partition. life sucks)).
After a quick look at the R code, I tried to bypass them by doing:

static void _installAttrib(SEXP obj, SEXP name, SEXP value) {
    /* to bypass dim & dimnames property checking */
    SEXP attr, cur_attr;
    PROTECT(attr = NEW_LIST(1));
    SETCAR(attr, value);
    SET_TAG(attr, name);
    if (ATTRIB(obj) == R_NilValue) SET_ATTRIB(obj, attr);
    else {
        cur_attr = nthcdr(ATTRIB(obj), length(ATTRIB(obj)) - 1);
        SETCDR(cur_attr, attr);
    }
    UNPROTECT(1);
}

but it crashes R. Is there any other way to do this other than copying
those code in R that was not included in the API ?

Thanks,
M. Manese



More information about the R-devel mailing list