Skip to content

Revdep: S3 generic/method consistency #6515

Open
@teunbrand

Description

@teunbrand

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>
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions