Skip to content

Revdep: S3 generic/method consistency #6515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
teunbrand opened this issue Jun 17, 2025 · 1 comment
Open

Revdep: S3 generic/method consistency #6515

teunbrand opened this issue Jun 17, 2025 · 1 comment

Comments

@teunbrand
Copy link
Collaborator

teunbrand commented Jun 17, 2025

Problem

This issue emerged from a reverse dependency check 9f80c8c.

We have updated some S3 generics like ggplot_build(), ggplot_add() and added ... as an argument. This allows for future expansion and is generally considered better practise than having a fixed set of arguments in a generic.

Ideally, methods follow the generic but having improved the generic, packages that have methods for this generic may now encounter the following warning:

checking S3 generic/method consistency ... WARNING
``
ggplot_build:
  function(plot, ...)
ggplot_build.<custom_class>:
  function(plot)
See section ‘Generic functions and methods’ in the ‘Writing R
Extensions’ manual.
``

The relevant part from the manual mentioned in the message is this:

A method must have all the arguments of the generic, including … if the generic does.

Solution

The solution would be to just include ... even if this is not used in the method. For example:

#' @export
ggplot_build.my_class <- function(plot, ...) {
  <your code>
}

For ggplot_add(), it depends whether you use the object_name argument or not.
If you do, you can use the following as template:

#' @export
ggplot_add.my_class <- function(object, plot, object_name, ...) {
  <your code>
}

And if you do not use the object_name argument, you can use:

#' @export
ggplot_add.my_class <- function(object, plot, ...) {
  <your code>
}
@teunbrand
Copy link
Collaborator Author

teunbrand commented Jun 17, 2025

Informed via email:

  • scatterpie
  • eks

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

No branches or pull requests

1 participant