[Rd] bypassing SET_DIM checking

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 14 00:10:41 CEST 2006


On Sun, 13 Aug 2006, Seth Falcon wrote:

> "miguel manese" <jjonphl at gmail.com> writes:
> 
> > 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:
> 
> If you want to emulate a matrix-like object you might want to look
> at the Matrix package which does uses S4 classes to represent
> matrices.

My guess (from earlier messages) is that the issue is rather that of an S3 
class akin to "data.frame".

> I don't think the class systems are fully functional at the C-level of
> R; macros like SET_DIM don't do dispatch beyond the built-in SEXP
> types.

They do no dispatch at all.  Rather, they are part of the internals of
attr<-, invoked e.g. by attr(x, "dim") <- newdim.  The class system is 
fully functional at a higher level in C, e.g. do_dimgets.

This is part of the internal integrity checks on attributes (and 
documented in detail in the R-exts manual in the R-devel version of R).  
Please don't use a "dim" attribute when those checks would be 
inappropriate, as code is written to rely on them.  E.g. a data frame does 
not have such an attribute, but does have a dim() method (but not a 
dim<-() method).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list