You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function assert() doesn't seem to be doing what is described in the documentation: The resulting assertion is successful, if combine is “or” (default) and at least one check evaluates to TRUE or combine is “and” and all checks evaluate to TRUE. Otherwise, assert throws an informative error message. I always get error messages, no matter what I do.
Did I understand something wrong or overlook something, or are theses errors in the function (or in the documentation)?
idCol<-"ID"
assert(
assert_character(idCol),
assert_numeric(idCol)
)
# I expect it to pass, but I get this error message:>Errorin eval(dots[[i]], envir=env) :>Assertionon'idCol'failed:Mustbeoftype'numeric', not'character'.
idCol<-"ID"
assert(
assert_character(idCol),
assert_subset(idCol, choices= c("ID", "id", "1"))
)
# I expect it to pass, but I get this error message:>Error:Assertionfailed.Oneofthefollowingmustapply:>* assert_character(idCol):ID>* assert_subset(idCol):ID
assert(
assert_character(idCol),
assert_subset(idCol, choices= c("ID", "id", "1")),
combine="and"
)
# I expect it to pass, but I get this error message:>Error:Assertionon'idCol'failed:ID.
You need to pass check_* functions into assert(), see the docs
library(checkmate)
idCol<-"ID"
assert(
assert_character(idCol),
assert_numeric(idCol)
)
#> Error:#> ! Assertion on 'idCol' failed: Must be of type 'numeric', not 'character'.
assert(
assert_character(idCol),
assert_subset(idCol, choices= c("ID", "id", "1"))
)
#> Error:#> ! Assertion failed. One of the following must apply:#> * assert_character(idCol): ID#> * assert_subset(idCol): ID
Activity
m-muecke commentedon Apr 16, 2026
You need to pass
check_*functions intoassert(), see the docsCreated on 2026-04-16 with reprex v2.1.1