Skip to content

how to add method to .Primitive function

2 messages · Vadim Ogranovich, Simon Urbanek

#
But then mylist is not a list:
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
#
On May 7, 2005, at 2:59 PM, Vadim Ogranovich wrote:

            
Well, then you can still use S3:
x <- list(x=1:5, y=5:1)
class(x) <- "mylist"
dim.mylist <- function(l) c(length(l[[1]]),length(l))
dim(x)
[1] 5 2
x[[1]]
[1] 1 2 3 4 5
is.list(x)
[1] TRUE

I'm not saying it's a good idea, because you can still break other  
things if you're not careful, but it's possible... If all you want is  
writing convenience functions for lists, that's fine, but I don't  
think you can replace data frames with such objects easily ...

Cheers,
Simon