Skip to content

ggplot_add.list() uses the %+% function instead of the + generic.  #5536

Open
@eliocamp

Description

@eliocamp

ggplot_add.list() adds each element of the list using %+% instead of + here:

ggplot_add.list <- function(object, plot, object_name) {
for (o in object) {
plot <- plot %+% o
}
plot
}

The idea is that ggplot() + list(e1, e2, e3) should be the same as ggplot() + e1 + e2 + e3, but this is not true if someone (😇) wanted to create a gg subclass with a custom + method.

I'm not sure why that code uses %+% instead of +. I modified the code and run tests both ways and everything passes. This logic has been since 3c16f9c from 2017

Would it be possible to change ggplot_add.list() to use the + generic? Barring that, would it be possible to make %+% an exported generic (same as +)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions