If given an object x
, is there a way to classify whether or not it is S3
or S4
(or "other")? I have looked at is.object()
and isS4()
, and can identify that something is an object (or not) and that it is an S4 object (or not). However, it doesn't seem to me that S3 objects are the complement of all objects that are not S4 objects.
Therefore, how can these assignments be done programmatically?
Here is an example of something that bugs me, taken from the help for is.object()
:
a = as.factor(1:3)
is.object(a) # TRUE
isS4(a) # FALSE
Does that mean that a
is an S3
object?
If it is an object and is not an S4 then it is an S3:
is.object(foo) & !isS4(foo)
is.object
checks for some magic OBJECT bit that gets set when the thing has a class attribute, so its essentially a fast way of doing any(names(attributes(foo))=="class")
, which is what defines an S3 object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With