Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message in expect_s3_class() is confusing #1322

Closed
DanChaltiel opened this issue Feb 7, 2021 · 1 comment
Closed

Error message in expect_s3_class() is confusing #1322

DanChaltiel opened this issue Feb 7, 2021 · 1 comment
Labels
expectation 🙀 feature a feature request or enhancement

Comments

@DanChaltiel
Copy link

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 /).

@hadley
Copy link
Member

hadley commented Feb 7, 2021

I think the best thing to do here would be to tweak the error message slightly:

Error: x$Sepal.Length inherits from `labelled/numeric` not `double`.
# ->
Error: x$Sepal.Length inherits from 'labelled'/'numeric' not 'double'.

@hadley hadley added expectation 🙀 feature a feature request or enhancement labels Feb 7, 2021
@hadley hadley closed this as completed in 00d2b16 Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expectation 🙀 feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants