Open hadley opened 11 months ago
Oh maybe method<-
could just return NULL
? — Nope that doesn't work because if the generic is defined in the current environment, it will reset it.
This almost works:
if (identical(environment(generic), parent.frame())) {
invisible(generic)
} else {
invisible(NULL)
}
But isn't quite right either.
Maybe we need to do some post-hoc clean up?
Something like this would work:
#' .onLoad <- function(...) {
#' S7::methods_register()
#' }
#' S7::package_clean_up()
Maybe if generic
is an external generic, return that object instead of the actual generic. Do something to these external generic objects on load.
Maybe this isn't as hard as I thought — method_register()
already has all the mechanics to return an external generic if needed, and there's no harm in that object continuing to live in the package namespace. (And in fact there's a small advantage in that we only need to create the external generic object once, rather than once each time).
I think this is going to be a problem because defining a method for a generic defined in another package will end up embedding a copy of that generic in your package. Not sure what we can do here given that this is a fairly deep seated behaviour of
<-
functions.