let type checks report actual *base* type, not classes
x <- structure(.Data = 1L, class = c("foo", "bar"))
check_character(x = x)
# [1] "Must be of type 'character', not 'foo/bar'"
str(x)
# Classes 'foo', 'bar' int 1
typeof(x)
# [1] "integer"
I find the above error message a little bit misleading; it reports the class of the offending input, though I expected the type from the first part of the error message.
This could be a little confusing to the user; in this case, classes c("foo", "bar") are actually not the problem, but the integer base type.
Maybe typeof() would be more intuitive here?
You are right that the message is not 100% to the point. However, using typeof() is problematic. If you attach a class to an atomic, you usually want it to be treated differently, independent of the underlying atomic structure. Many base types are constructed by just adding an attribute like class:
- Factors are integers with class "factor"
- Matricies are numeric vectors with attribute "dim"
- Data frames are lists with class "data.frame" and "RowNamesSymbol"
I will try to improve the error message though.