Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Make a existing function generic

$
0
0

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.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>