From vograno at evafunds.com  Sat May  7 20:59:04 2005
From: vograno at evafunds.com (Vadim Ogranovich)
Date: Sat May  7 20:59:12 2005
Subject: [Rd] how to add method to .Primitive function
Message-ID: <C698D707214E6F4AB39AB7096C3DE5A59E9334@phost015.EVAFUNDS.intermedia.net>

But then mylist is not a list:
> x <- new("mylist", x = list(x = 1, y = 2))
> x[[1]]
Error in x[[1]] : subscript out of bounds

This is probably solvable by a sprinkle of setIs or setAs spells, but
each time I get into the S4 area I feel walking a mine-field.

All this exercise on my part was to write a list-based
lightweight.data.frame class, which would be more efficient than the
data.frame.
I'd pondered this idea some time ago and now again came back to it
frustrated by the slowness of the data.frame. But it seems I am not up
to the task.

Thank you for helping anyway,
Vadim

> -----Original Message-----
> From: Gabor Grothendieck [mailto:ggrothendieck@gmail.com] 
> Sent: Saturday, May 07, 2005 8:56 AM
> To: Vadim Ogranovich
> Cc: r-devel@stat.math.ethz.ch
> Subject: Re: [Rd] how to add method to .Primitive function
> 
> On 5/7/05, Vadim Ogranovich <vograno@evafunds.com> 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")?
> 
> The list method of dim is sealed 
> 
> > isSealedMethod("dim", "list")
> [1] TRUE
> 
> but you could define a subclass, mylist, and use that:
> 
> > setClass("mylist", representation(x = "list"), contains = "list")
> [1] "mylist"
> > setMethod("dim", "mylist", function(x) c(length(x@x[[1]]), 
> > length(x@x)))
> [1] "dim"
> > x <- new("mylist", x = list(x = 1, y = 2))
> > dim(x)
> [1] 1 2
>


[Rd] how to add method to .Primitive function
Vadim Ogranovich