setClass
for normal code development.classLabel(Class)
.classEnv(Class, default = .requirePackage("methods"), mustFind = TRUE)testVirtual(properties, extends, prototype, where)
makePrototypeFromClassDef(slots, ClassDef, extends, where)
newEmptyObject()
completeClassDefinition(Class, ClassDef, where, doExtends)
getAllSuperClasses(ClassDef, simpleOnly = TRUE)
superClassDepth(ClassDef, soFar, simpleOnly = TRUE)
isVirtualClass(Class, where)
newBasic(Class, ...)
makeExtends(Class, to, coerce, test, replace, by, package, slots,
classDef1, classDef2)
reconcilePropertiesAndPrototype(name, properties, prototype,
superClasses, where)
tryNew(Class, where)
empty.dump()
showClass(Class, complete=TRUE, propertiesAreCalled="Slots")
showExtends(ext, printTo = stdout())
possibleExtends(class1, class2, ClassDef1 = getClassDef(class1),
ClassDef2 = getClassDef(class2, where =
.classEnv(ClassDef1)))
completeExtends(ClassDef, class2, extensionDef, where)
classMetaName(name)
methodsPackageMetaName(prefix, name, package = "")
metaNameUndo(strings, prefix, searchForm = FALSE)
requireMethods(functions, signature, message, where)
checkAtAssignment(cl, name, valueClass)
checkSlotAssignment(obj, name, value)
defaultPrototype()
isClassDef(object)
validSlotNames(names)
getDataPart(object)
setDataPart(object, value, check = TRUE)
testVirtual
:"VIRTUAL"
. Otherwise, a class is virtual only if it has no slots, extends no
non-virtual classes, and has a NULL
Prototype.
makePrototypeFromClassDef
:ClassDef
, if there is
one, is used instead (but it must be coercible to the class of
the slot). This includes the data part (".Data"
slot) if
there is one. NULL
.
newEmptyObject
:"NULL"
. Later version should create a special object reference that marks
an object currently with no slots and no data.
completeClassDefinition
:Class
, relative to the class
definitions visible from environment where
. If
doExtends
is TRUE
, complete the super- and
sub-class information. This function is called when a class is defined or re-defined.
getFromClassDef
:getSlots
:x
can either be the name of
a class or the class definition object.
getAllSuperClasses
, superClassDepth
:getAllSuperClasses
is a utility function used to complete a
class definition. It returns all the superclasses reachable from
this class, in breadth-first order (which is the order used for
matching methods); that is, the first direct superclass followed
by all its superclasses, then the next, etc. (The order is
relevant only in the case that some of the superclasses have
multiple inheritance.) superClassDepth
, which is called from
getAllSuperClasses
, returns the same information, but as a
list with components label
and depth
, the latter for
the number of generations back each class is in the inheritance
tree. The argument soFar
is used to avoid loops in the
network of class relationships.
isVirtualClass
:assignClassDef
:newBasic
:new
for basic classes
that don't have a formal definition. Any of these could have a formal definition, except for
Class="NULL"
(disallowed because NULL
can't have
attributes). For all cases except "NULL"
, the class of the
result will be set to Class
. See new
for the interpretation of the arguments.
makeExtends
:reconcilePropertiesAndPrototype
:new(classi)
for the class,
classi
of the slot if that succeeds, and NULL
otherwise. The prototype may imply slots not in the properties list, since
properties does not include inherited slots (these are left
unresolved until the class is used in a session).
tryNew
:NULL
. This is inefficient and also not a good idea when actually
generating objects, but is useful in the initial definition of
classes.
showClass
:complete
is TRUE
, include the indirect
information about extensions. It is the utility called from show(getClass(.))
,
and the user should typically use getClass(.)
for looking
at class definitions.
showExtends
:printTo = FALSE
,
returns a list with components what
and how
; this is
used e.g., by promptClass()
.
possibleExtends
:
containing various
functions to test and/or coerce the relationship.
classLabel
: .classEnv
: Class
has been defined. Class
should typically be
the result of class()
(and hence contain a
"package"
attribute) or getClass
(or
getClassDef
).
completeExtends
:class2
and extensionDef
are included, this
class relation is to be added. Otherwise just use the current
ClassDef
. Both the contains
and subclasses
slots are
completed with any indirect relations visible.
classMetaName
:methodsPackageMetaName
:metaNameUndo
.
requireMethods
:setMethod
will be called to define a
method that throws an error, with the supplied message. The requireMethods
function allows virtual classes to
require actual classes that extend them to implement methods for
certain functions, in effect creating an API for the virtual class. Otherwise, default methods for the corresponding function would be
called, resulting in less helpful error messages or (worse still)
silently incorrect results.
checkSlotAssignment
, checkAtAssignment
:slot<-
with the argument check=FALSE
, to prevent the call to
checkSlotAssignment
.
defaultPrototype
:class
and its (R internal) type,
typeof()
, are "S4"
.
.InitBasicClasses
, .InitMethodsListClass
, .setCoerceGeneric
:.onLoad
.
isClassDef
:object
a representation of a class?
validSlotNames
:names
unless one of the names is reserved, in which
case there is an error. (As of writing, "class"
is the
only reserved slot name.)
getDataPart
, setDataPart
:object@.Data
. Calls to setDataPart
are also used
to merge the data part of a superclass prototype.
typeof(defaultPrototype()) #-> "S4"
## .classEnv()
meth.ns <- asNamespace("methods")
if(get4 <- !any("package:stats4" == search()))
require("stats4")
stopifnot(TRUE
, identical(.classEnv("data.frame"), meth.ns)
, identical(.classEnv(class(new("data.frame"))), meth.ns)
, identical(.classEnv( "mle" ), meth.ns) # <- *not* 'stats4'
, identical(.classEnv(class(new("mle"))), asNamespace("stats4"))
, identical(.classEnv(getClass ("mle") ), asNamespace("stats4"))
)
if(get4) detach("package:stats4")
Run the code above in your browser using DataLab