Henrik Bengtsson has provided the internet with a nice way of creating S3 generics in R without having to bother whether they were already created before... in 2002.
What his function setGenericsS3 does, is basically:
if so,
if not, just create the generic.
This code proved very useful to automatically create generics when there was none available in your own packages. As we moved quite past this R era, I was wondering what the correct way is to achieve the same in R now. I can't find an isS3Generic()
or similar function in R, and the code of Henrik Bengtsson originates from long before the obligatory namespaces as introduced in R 2.14. I remember I've seen other ways of achieving the same, but can't locate them.
EDIT : I'm specifically looking for S3. The function isGeneric()
only works for S4, eg for anova
(which is a S3 generic) :
> isGeneric('anova')
[1] FALSE
> anova
function (object, ...)
UseMethod("anova")
<bytecode: 0x04dc7a18>
<environment: namespace:stats>
You can use isGenericS3
function of the R.methodsS3
package. Please see the code below:
library(R.methodsS3)
isGenericS3(anova)
# [1] TRUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With