-
Notifications
You must be signed in to change notification settings - Fork 339
Closed
Labels
Description
In some cases, you want to remove a class from an object.
Then, if you removed the last S3 class, you should obviously expect an object without any S3 class.
However, expect_s3_class() will not allow testing if an object is no longer an S3 class.
Here is a simple example with labels, using expss:::unlab.default():
library(expss)
library(testthat)
x=iris
class(x$Sepal.Length)
#> [1] "numeric"
var_lab(x$Sepal.Length) = "Sepal length"
var_lab(x$Sepal.Length)
#> [1] "Sepal length"
class(x$Sepal.Length)
#> [1] "labelled" "numeric"
expect_s3_class(x$Sepal.Length, "labelled/numeric")
#> Error: x$Sepal.Length inherits from `labelled/numeric` not `labelled/numeric`.
x$Sepal.Length = unlab(x$Sepal.Length)
class(x$Sepal.Length)
#> [1] "numeric"
expect_s3_class(x$Sepal.Length, "numeric")
#> Error: x$Sepal.Length is not an S3 object
expect_s3_class(x$Sepal.Length, NULL)
#> Error in expect_s3_class(x$Sepal.Length, NULL): is.character(class) is not TRUECreated on 2021-02-07 by the reprex package (v1.0.0)
Here are some potential syntaxes I could think of:
expect_s3_class(x$Sepal.Length, NULL)expect_s3_class(x$Sepal.Length, isS3=FALSE)expect_not_s3(x$Sepal.Length)
IMHO, the first one feels the most logical and should be the easiest to implement.
EDIT:
As you can see, I've been confused by the error message "Error: x$Sepal.Length inherits from labelled/numeric not labelled/numeric.". See #1322.
Reactions are currently unavailable