From ripley at stats.ox.ac.uk  Sat May  7 17:41:57 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sat May  7 17:42:06 2005
Subject: [Rd] how to add method to .Primitive function
In-Reply-To: <C698D707214E6F4AB39AB7096C3DE5A59E9333@phost015.EVAFUNDS.intermedia.net>
References: <C698D707214E6F4AB39AB7096C3DE5A59E9333@phost015.EVAFUNDS.intermedia.net>
Message-ID: <Pine.LNX.4.61.0505071636550.17532@gannet.stats>

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


[Rd] how to add method to .Primitive function
Prof Brian Ripley