I want to make an existing function generic. Thereby the default case should be the same as before, but I want to add a case for my own data structure.
Thereby I came around setGeneric
. For classes like data.frame
it works like expected, but for my own class (class attribute set) it just calls the default function:
> setGeneric('dim')
> dim.data.frame <- function(x) 42
> df <- read.csv('test.csv')
> dim(df)
42
If I exchange data.frame
with my own class it doesn't work and just calls the default dim
function.