mllg / checkmate

Fast and versatile argument checks
https://mllg.github.io/checkmate/
Other
265 stars 30 forks source link

unwanted warning with `makeAssertCollection` #242

Open TanguyBarthelemy opened 1 year ago

TanguyBarthelemy commented 1 year ago

I'm trying to group my assertion with the functions makeAssertCollection and reportAssertions. Only, I realized that for some values, the function reportAssertions adds unwanted warnings.

Here is a simple example with two functions that are doing the same job : testing if x is an int

library("checkmate")

f1 <- function(x) {
    x_corr <- checkmate::assert_int(
        x = x, coerce = TRUE)
    return(invisible(x_corr))
}

f2 <- function(x) {
    coll <- checkmate::makeAssertCollection()
    x_corr <- checkmate::assert_int(
        x = x, coerce = TRUE, add = coll)
    checkmate::reportAssertions(coll)
    return(invisible(x_corr))
}

With x = Inf :

f1(x = Inf)
Error in f1(Inf) :
Assertion on 'x' failed: Must be of type 'single integerish value', not 'double'.
f2(x = Inf)
Error in f2(Inf) : 1 assertions failed:
 * Variable 'x': Must be of type 'single integerish value', not 'double'.
In addition: Warning message:
In setNames(as.integer(round(x, 0L)), names(x)) :
  NAs introduced by coercion to integer range

Is it possible to suppress these warnings (which are not related to the evaluation of the assertion for the variable x)?