Re: [R] getting lapply() to work for a new class

2007-08-15 Thread Prof Brian Ripley
On Wed, 15 Aug 2007, Pijus Virketis wrote: > Thank you. > > When I tried to set as.list() in baseenv(), I learned that its bindings > are locked. Of course. Did you not see my comment about 'to protect code against redefining functions'? > Does this mean that the thing to do is just to write m

Re: [R] getting lapply() to work for a new class

2007-08-15 Thread Martin Morgan
Pijus, My 2 cents, which might be post-hoc rationalization. If your class 'is' a list, with additional information, then setClass("Test", contains="list") and you're ready to go. On the other hand, if your class 'has' a list, along with other information, create an accessor setGeneric("test",

Re: [R] getting lapply() to work for a new class

2007-08-15 Thread Pijus Virketis
Thank you. When I tried to set as.list() in baseenv(), I learned that its bindings are locked. Does this mean that the thing to do is just to write my own "lapply", which does the coercion using my "private" as.list(), and then invokes the base lapply()? -P -Original Message- From: Prof

Re: [R] getting lapply() to work for a new class

2007-08-15 Thread Prof Brian Ripley
On Wed, 15 Aug 2007, Pijus Virketis wrote: > I would like to get lapply() to work in the natural way on a class I've > defined. What you have not said is that this is an S4 class. > As far as I can tell, lapply() needs the class to be coercible > to a list. Even after I define as.list() and as.v

[R] getting lapply() to work for a new class

2007-08-15 Thread Pijus Virketis
Hi, I would like to get lapply() to work in the natural way on a class I've defined. As far as I can tell, lapply() needs the class to be coercible to a list. Even after I define as.list() and as.vector(x, mode="list") methods, though, I still get an "Error in as.vector(x, "list") : cannot coerce