Skip to content

Error message in expect_s3_class() is confusing #1322

@DanChaltiel

Description

@DanChaltiel

During testing, it can be common to make some trial-and-error.

This can lead to this kind of awkward error message.

library(testthat)
x=iris
class(x$Sepal.Length)
#> [1] "numeric"
typeof(x$Sepal.Length)
#> [1] "double"
expss::var_lab(x$Sepal.Length) = "Sepal length"

#lets say I mixed the concepts of classes and types
expect_s3_class(x$Sepal.Length, "double")
#> Error: x$Sepal.Length inherits from `labelled/numeric` not `double`.

expect_s3_class(x$Sepal.Length, "labelled/numeric")
#> Error: x$Sepal.Length inherits from `labelled/numeric` not `labelled/numeric`.

Created on 2021-02-07 by the reprex package (v1.0.0)

Maybe this function can either accept this syntax or specifically handle this situation (for instance by throwing a special message when a class contains /).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions