I have a special s3 class object with class myobj. It has defined methods for select, filter, and collect—e.g. select.myobj, filter.myobj, and collect.myobj. The goal is to have them be methods that feel and look like dplyr.
These methods do not require the use of dplyr so dplyr is not suggested. I want the methods to always be available when the package is imported. The only way that I'm aware of doing this is declaring them as methods like such
select <- function(x, ...) UseMethod("select")
select.myobj <- function(x, ...) { some code here}
When this is done, the methods will collide with dplyr is loaded. The alternative is to suggest dplyr and use vctrs::s3_register(). But then the methods will only be available when dplyr is installed.
Is there a way to get the best of both worlds? Is it possible to conditionally define the generic? For example if dplyr isn't available export the generic?