Skip to content
Prev 247240 / 398503 Next

s3 methods on S4 objects

On 01/12/2011 10:54 PM, steven mosher wrote:
Hi Steven --

This works for  me

setClass("A", representation=representation(df="data.frame"))

setMethod("as.data.frame", "A",
    function(x, row.names=NULL, optional=FALSE, ...)
{
    ## implementation, e.g.,
    callGeneric(x at df, row.names=row.names, optional=optional, ...)
})
Object of class "data.frame"
data frame with 0 columns and 0 rows
V1 V2 V3 V4 V5
1  0  0  0  0  0
2  0  0  0  0  0
3  0  0  0  0  0


Maybe you call setGeneric (no need to, setMethod will promote
as.data.frame automatically) in a way that does not specify the default
(arg useAsDefault) correctly?

Martin