[Rd] how to add method to .Primitive function

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat May 7 17:41:57 CEST 2005


On Sat, 7 May 2005, Vadim Ogranovich wrote:

> I tried to write the dim method for the list class, but R doesn't seem
> to dispatch to it:
>> dim.list = function(x) c(length(x[[1]]), length(x))
>> dim(list(1))
> NULL
>> dim.list(list(1))
> [1] 1 1
>
> What is the correct way of registering dim.list with .Primitive("dim")?

You really don't want to be doing this: the standard dim() function is 
intended to work with lists and is used e.g. for matrix lists.
So you are in danger of breaking things.

For that reason and for performance reasons, the internal dispatch only 
works on explicit class attributes as given by oldClass(), not the 
implicit ones given by class().


-- 
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