Skip to content

Revdep: checking for classes #6498

Open
@teunbrand

Description

@teunbrand

Problem

This issue emerged from a recent revdepcheck (de2715d), and affects an estimated 91 reverse dependencies.
The issue is that tests based on ggplot2's classes fail because we transitioned to S7 classes.

It includes tests for the class itself

expect_equal(class(p), c("gg", "ggplot"))

But also tests that relate to class structure like so:

expect_length(p, 11)
expect_type(p, "list")

The following case works for now, but we might remove the manual "ggplot" S3 class in the future. It is not the recommended way of testing.

expect_s3_class(p, "ggplot")`

This pattern may hold for other classes, like mapping, labels, margin or elements too.

Solution

There are several possibilities for adjusting the test.

  • The preferred way is to use expect_true(is_ggplot(p)). The is_ggplot() function is internally consistent regardless of whether the ggplot object is the old or new class.
  • Alternatively, you can use expect_true(inherits(p, c("ggplot", "ggplot2::ggplot"))), which requires a match to one of the two classes.
  • Lastly, you can use expect_s7_class(p, class_ggplot), but that will only be stable after we've released the new version. It is not suitable for backward compatibility.

Unfortunately, this is not something that is straightforward to fix in ggplot2, so this probably will have to be updated in the reverse dependencies.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions