I am working on a pet project in R that builds out a custom S3 class named groupr
. I have written a few functions with dot notation (print.groupr
, subset.groupr
) as described in the Hadley tutorial, but I would like to extend the apply
function and cannot find a way to do so.
As demonstrated in the tutorial, the pryr
package provides a hint. I see that the subset
and print
function are different function types like so:
> pryr::ftype(subset)
[1] "s3" "generic"
> pryr::ftype(apply)
[1] "function"
Additionally, the subset
function prints this in the terminal:
function (x, ...)
UseMethod("subset")
<bytecode: 0x115f0ab88>
<environment: namespace:base>
But the apply
function prints its entire source code. I believe I understand why this is happening - the print
, subset
, plot
, etc functions are S3 functions and apply
is a boring old normal function - but I don't see any way to extend the apply
function without "overwriting" the base function. For example, UseMethod("apply")
points the function call to my groupr
namespace when the package is loaded.
Does anyone know how to address this? Namely, the family of apply
functions are not S3 objects and cannot be extended using dot notation. Does anyone know how to write apply.myclass
, apply.myotherclass
functions?