Skip to content

Declare S7 imports and update package hooks - #107

Merged
thomasp85 merged 18 commits into
r-lib:mainfrom
t-kalinowski:fix/s7-compatibility-20261012
Nov 11, 2026
Merged

thomasp85 merged 18 commits into
r-lib:mainfrom
t-kalinowski:fix/s7-compatibility-20261012

Conversation

@t-kalinowski

@t-kalinowski t-kalinowski commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Marquee declares S7 in Imports and uses its APIs when registering ggplot2 methods, but NAMESPACE does not import from S7. Add an explicit S7_inherits import in the roxygen package declarations and regenerate NAMESPACE to remove the dependency check note.

Use the S7 load, build, and unload hooks when exported by the installed S7. Unloading removes this package's dependency hooks and owned methods on external S7 generics. The existing S7 version requirement is preserved. Method registration follows the existing deferred load work.

@t-kalinowski

Copy link
Copy Markdown
Member Author

Thanks for maintaining marquee! I'm planning to submit the next version of S7 to CRAN on November 16 (see RConsortium/S7#786).

Would you be able to merge these compatibility changes and submit an updated version of marquee to CRAN before then? Please let me know if you need more time or if there’s anything I can help with.

@thomasp85

Copy link
Copy Markdown
Member

Thanks for putting this together! Sorry it took some time to get to...

However, I've run into one issue when testing locally with S7 0.2.0 (current CRAN): the PR introduces an unsuppressible startup message.

Reprex, with this branch installed:

suppressPackageStartupMessages(library(marquee))
#> Overwriting method merge_element(<ggplot2::element_text>, S3<element_marquee>)

On main, the message does not appear. Because the message is emitted with message() from regular code during .onLoad() (not wrapped in packageStartupMessage()), it can't be suppressed and triggers the R CMD check NOTE "startup messages cannot be suppressed", which CRAN will flag.

Do you have any advice for how to approach this?

@teunbrand

Copy link
Copy Markdown
Contributor

Do you have any advice for how to approach this?

I think your issue might be similar as I had in ggarrow, where we both dynamically register S7 methods in on_load(), e.g. here:

marquee/R/element_marquee.R

Lines 239 to 252 in 3a12ffc

if (requireNamespace("ggplot2", quietly = TRUE)) {
if (S7::S7_inherits(ggplot2::element_text)) {
merge_element <- ggplot2::merge_element
S7::method(
merge_element,
list(ggplot2::element_text, S7::new_S3_class("element_marquee"))
) <- function(new, old) {
idx <- lengths(S7::props(new)) == 0
idx <- names(idx[idx])
S7::props(new)[idx] <- unclass(old)[idx]
new
}
}
}

The solution I had was removing the else {S7::methods_register()} branch and follow rlang::on_load() orthodoxy, which looked like this: teunbrand/ggarrow@740e70c.

marquee registers its merge_element() method at load time inside
rlang::on_load(). The fallback registered it again with released S7,
causing an overwrite message and an R CMD check NOTE. Removing the
fallback restores the previous behavior while retaining S7_on_load()
when available.
@t-kalinowski

Copy link
Copy Markdown
Member Author

Thanks @thomasp85 for testing and @teunbrand for the diagnosis. marquee does something a little different from most packages: it doesn't call method<- at package build time, but instead registers methods at load time using rlang::on_load(). So the standard guidance of calling methods_register() from .onLoad() doesn't apply here: the methods_register() call effectively re-registers a method that was just registered by rlang::on_load(). It looked like one of the two registrations needed to go, and removing the S7 one (methods_register()) seemed like the simpler fix. I've pushed a commit doing that.

The change I pushed looks like this:

 .onLoad <- function(...) {
   run_on_load()
   if ("S7_on_load" %in% getNamespaceExports("S7")) {
     getExportedValue("S7", "S7_on_load")()
-  } else {
-    S7::methods_register()
   }
 }

I tested this locally with S7 0.2.2 and development S7: suppressPackageStartupMessages(library(marquee)) produces no message, and the merge_element() method still dispatches. Please let me know if you'd prefer a different approach.

@thomasp85
thomasp85 merged commit d5bd1e6 into r-lib:main Nov 11, 2026
7 of 13 checks passed
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.

6 participants