S4 类(和参考类,就此而言,也许让一些人感到懊恼)是使用 S4 类定义的(很酷(?)嗯?)
> class(trajclass)
[1] "classRepresentation"
attr(,"package")
[1] "methods"
> getClass(class(trajclass))
Class "classRepresentation" [package "methods"]
Slots:
Name: slots contains virtual prototype
Class: list list logical ANY
Name: validity access className package
Class: OptionalFunction list character character
Name: subclasses versionKey sealed
Class: list externalptr logical
Known Subclasses: "ClassUnionRepresentation", "refClassRepresentation"
我认为你能做的最好的就是沿着
isS4(trajclass) && !is(trajclass, "classRepresentation")
S4show
用作 ; 的同义词(某种)print
。有一个 S4show
方法classRepresentation
是
> selectMethod(show, class(traj))
Method Definition:
function (object)
{
cat(gettextf("Class generator function for class \"%s\" from package \"%s\"\n",
object@className, object@package))
show(as(object, "function"))
}
<bytecode: 0x1522d40>
<environment: 0xf1d808>
Signatures:
object
target "classGeneratorFunction"
defined "classGeneratorFunction"
而 for 的show
方法trajobject
是默认的,即
> selectMethod(show, class(trajobject))
Method Definition (Class "derivedDefaultMethod"):
function (object)
showDefault(object, FALSE)
<bytecode: 0x1516d08>
<environment: namespace:methods>
Signatures:
object
target "Trajectories"
defined "ANY"
里面有肉methods::showDefault
。我想你可以实现
setGeneric("isNotS4ClassDef",
function(object) standardGeneric("isNotS4ClassDef"))
setMethod(isNotS4ClassDef, "ANY",
function(object) TRUE)
setMethod(isNotS4ClassDef, "classRepresentation",
function(object) FALSE)