Skip to content

Signal method overwrites as package startup messages - #794

Closed
t-kalinowski wants to merge 3 commits into
mainfrom
fix/suppressible-overwrite-message
Closed

t-kalinowski wants to merge 3 commits into
mainfrom
fix/suppressible-overwrite-message

Conversation

@t-kalinowski

Copy link
Copy Markdown
Member

Method overwrite notices now use packageStartupMessage(), so they can be suppressed during package loading. This avoids the R CMD check NOTE "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>) through suppressPackageStartupMessages().

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 with suppressPackageStartupMessages() or handled as a packageStartupMessage.

This change does not affect packages running against released S7 0.2.x.

Internal changes

generic_add_method() now uses packageStartupMessage(), 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 through S7_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 retain message() elsewhere. Detection would need to account for S7's hook replays, direct method<- calls in .onLoad(), and devtools::load_all(), which does not call loadNamespace(). 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 that suppressPackageStartupMessages() can also silence an overwrite notice outside package loading.

Testing

The full test suite passes locally with devtools::test().

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.
@hadley

hadley commented Nov 10, 2026

Copy link
Copy Markdown
Member

Are you sure this is needed? Isn't the fix to eliminate the duplicate method registration?

@t-kalinowski

Copy link
Copy Markdown
Member Author

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 packageStartupMessage(), but also because it will make it easier to silence messages like this if it comes up in another scenario that's less clear cut. That said, I can just as easily see the value in keeping the notice hard to silence so these problems surface. I'll close this.

@hadley

hadley commented Nov 10, 2026

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants