How do I test if an object is a instance of an S4 class (not sure if this is the right terminology)? I know about the function isS4 however, this also returns true for class definitions, etc. E.g.:
traj <- setClass(
Class="Trajectories",
representation=representation(
times = "numeric",
traj = "matrix"
)
)
trajclass <- getClass("Trajectories")
trajobject <- new(Class="Trajectories",times=c(1,3),traj=matrix(1:4,ncol=2))
isS4(traj)
isS4(trajclass)
isS4(trajobject)
I am only interested in objects containing data, trajobject in this case; not so much in methods or class definitions. Is there a native function that I can use to test if an S4 object is an actual object? I.e. when using print(object) the output starts with:
An object of class “foo”…..
S4 classes (and reference classes, for that matter and perhaps to the chagrin of some) are defined using S4 classes (cool (?) eh?)
I think the best you could do is along the lines of
S4 uses
showas a synonym (sort of) forprint; there is an S4showmethod forclassRepresentationthat iswhereas the
showmethod fortrajobjectis the default, which iswith the meat in
methods::showDefault. I guess you could implement