[R] getting lapply() to work for a new class
pvirketis at hbk.com
Wed Aug 15 23:56:56 CEST 2007
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()?
From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
Sent: Wednesday, August 15, 2007 5:18 PM
> 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 to vector". What am I doing wrong?
Not considering namespaces. Setting an S4 method for as.list() creates
an object called as.list in your workspace, but the lapply function uses
the as.list in the base namespace. That's the whole point of
namespaces: to protect code against redefining functions.
More information about the R-help