Repository navigation
Signal method overwrites as package startup messages - #794
t-kalinowski wants to merge 3 commits into
Conversation
A package can register a method while it loads and then call S7_on_load(), which re-registers the same method. Released S7 printed "Overwriting method" for this sequence (r-lib/marquee#107). Re-registering an identical method has been silent since #474. Cover the S7_on_load() sequence directly.
Methods are often registered while a package loads. The "Overwriting method" notice used message(), so suppressPackageStartupMessages() could not silence it and R CMD check reported a NOTE for the loading package. Use packageStartupMessage(), as base R does for overwritten S3 methods. The notice displays as before outside package loading.
|
Are you sure this is needed? Isn't the fix to eliminate the duplicate method registration? |
|
Agreed, this isn't needed; the duplicate registration was the real problem, and that's fixed in r-lib/marquee#107. Still, I saw value in having a patch here, mostly because it matches S3's use of |
|
Just switching unconditionally to package startup messages doesn't feel quite right, and doing all the work to differentiate which is which doesn't seem worth the effort. We can revisit in the future if it comes up again. |
Method overwrite notices now use
packageStartupMessage(), so they can be suppressed during package loading. This avoids theR CMD checkNOTE "startup messages cannot be suppressed" when a genuine overwrite occurs during load.The report in r-lib/marquee#107 involved an identical method being registered twice. That case is already silent on main (#474). Genuine overwrites during load still produce a notice: for example, reloading ggplot2 4.0.3 in one session printed
Overwriting method +(<ggplot2::ggplot>, <ANY>)throughsuppressPackageStartupMessages().Public-facing change
The notice text is unchanged. It still prints outside package loading and can still be silenced with
suppressMessages(). It can now also be silenced withsuppressPackageStartupMessages()or handled as apackageStartupMessage.This change does not affect packages running against released S7 0.2.x.
Internal changes
generic_add_method()now usespackageStartupMessage(), as base R does for its S3 method overwrite notice. Tests cover suppression of an overwrite notice and silent re-registration of an identical method throughS7_on_load(). The existing message snapshot is unchanged, and a NEWS bullet describes the change.Alternative considered
S7 could use
packageStartupMessage()only during package loading and retainmessage()elsewhere. Detection would need to account for S7's hook replays, directmethod<-calls in.onLoad(), anddevtools::load_all(), which does not callloadNamespace(). Flagging only S7's hook replays would miss direct calls. A missed case could make the notice unsuppressible during load and bring back the check NOTE.Using
packageStartupMessage()unconditionally avoids that detection. The tradeoff is thatsuppressPackageStartupMessages()can also silence an overwrite notice outside package loading.Testing
The full test suite passes locally with
devtools::test().