quickcheck icon indicating copy to clipboard operation
quickcheck copied to clipboard

`factor_(any_na = TRUE)` may return integer, not factor

Open eitsupi opened this issue 1 year ago • 0 comments

I believe it is converted to integer in the process of inserting NA.

quickcheck::for_all(
  factors = quickcheck::factor_(any_na = TRUE),
  property = function(factors) {
    print(factors)
    testthat::expect_s3_class(factors, "factor")
  }
)
#> [1]  1  1  1 NA  1
#> [1] D'9
#> Levels: D'9
#> [1] Q3[b-@+@ >!Uraq   /8 {
#> Levels: Q3[b-@+@ >!Uraq /8 {
#> [1] NA NA NA  1
#> [1] ~;W|u
#> Levels: ~;W|u
#> [1] NA NA NA
#> [1] W\\
#> Levels: W\\
#> [1]  1 NA
#> [1] NA
#> [1] B&5&@#
#> Levels: B&5&@#
#> [1] NA
#> [1] NA
#> [1] NA
#> Error: Falsifiable after 1 tests, and 6 shrinks
#> <expectation_failure/expectation/error/condition>
#> `factors` is not an S3 object
#> Backtrace:
#>      ▆
#>   1. └─quickcheck::for_all(...)
#>   2.   └─hedgehog::forall(...)
#>   3.     └─hedgehog:::run.prop(property, counterexample$smallest, curry)
#>   4.       ├─base::tryCatch(...)
#>   5.       │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>   6.       │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>   7.       │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>   8.       ├─base::withCallingHandlers(...)
#>   9.       ├─base::do.call(property, arguments)
#>  10.       └─global `<fn>`(factors = NA_integer_)
#>  11.         └─testthat::expect_s3_class(factors, "factor")
#> Counterexample:
#> $factors
#> [1] NA

Created on 2024-10-19 with reprex v2.1.1

eitsupi avatar Oct 19 '24 12:10 eitsupi