You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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).
#390 (comment) suggests that the mere presence of an object (not a function) is sufficient to trigger some of the problems. And since package bindings are locked by the time we get to .onLoad() we can't just assign a sentinel and then later remove it in register_methods().
Activity
hadley commentedon Sep 16, 2023
Oh maybe
method<-could just returnNULL? — Nope that doesn't work because if the generic is defined in the current environment, it will reset it.This almost works:
But isn't quite right either.
Maybe we need to do some post-hoc clean up?
hadley commentedon Oct 16, 2023
Something like this would work:
hadley commentedon Oct 16, 2023
Maybe if
genericis an external generic, return that object instead of the actual generic. Do something to these external generic objects on load.hadley commentedon Nov 27, 2023
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).Don't embed external generics
[-]Embedding generics when defining methods[/-][+]Generic are embedded when defining methods[/+][-]Generic are embedded when defining methods[/-][+]Generics are embedded when defining methods[/+]hadley commentedon May 22, 2026
#390 (comment) suggests that the mere presence of an object (not a function) is sufficient to trigger some of the problems. And since package bindings are locked by the time we get to
.onLoad()we can't just assign a sentinel and then later remove it inregister_methods().Strip external generics on build (RConsortium#662)