Skip to content

load_all() overwrites method update_ggplot() twice #330

@dmuenz

Description

@dmuenz

My package creates a new method for ggplot2's S7 generic update_ggplot. When I call devtools::load_all("."), I get a message saying my update_ggplot method is being overwritten. The issue is that this message is printed twice, which makes me think either I or devtools/roxygen2/ggplot2/S7 is doing something wrong.

Here's a small example, where the following is the only R code in a package named mypackage:

#' @export
do_nothing <- S7::new_class("do_nothing")

# Enable adding a do_nothing object to a ggplot with `+`
#' @importFrom ggplot2 update_ggplot
S7::method(update_ggplot, list(do_nothing, ggplot2::class_ggplot)) <-
  function(object, plot, ...) { plot }

.onLoad <- function(...) {
  S7::methods_register()
}

When I call load_all(), the following is printed to the console:

ℹ Loading mypackage
Overwriting method update_ggplot(<mypackage::do_nothing>, <ggplot2::ggplot>)
Overwriting method update_ggplot(<mypackage::do_nothing>, <ggplot2::ggplot>)

My actual package also implements custom methods for ggplot_build and ggplot_gtable, but these do not have the same issue. Actually, for these two methods, no note at all is printed to the console. All three methods produce the expected output, so the issue is just that the notes make me think that update_ggplot is being defined or called too many times.

Is there something wrong with my code? Is this a bug in some package (and forgive me if I'm posting this in the wrong place)? Or is this expected behavior?

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