- name
The name of the class, as a string. The result of calling
new_class()
should always be assigned to a variable with this name,
i.e. foo <- new_class("foo")
.
- parent
The parent class to inherit behavior from.
There are three options:
An S7 class, like S7_object.
An S3 class wrapped by new_S3_class()
.
A base type, like class_logical, class_integer, etc.
- package
Package name. It is good practice to set the package
name when exporting an S7 class from a package because it prevents
clashes if two packages happen to export a class with the same
name.
Setting package
implies that the class is available for external use,
so should be accompanied by exporting the constructor. Learn more
in vignette("packages")
.
- properties
A named list specifying the properties (data) that
belong to each instance of the class. Each element of the list can
either be a type specification (processed by as_class()
) or a
full property specification created new_property()
.
- abstract
Is this an abstract class? An abstract class can not be
instantiated.
- constructor
The constructor function. In most cases, you can rely
on the default constructor, which will generate a function with one
argument for each property.
A custom constructor should call new_object()
to create the S7 object.
The first argument, .data
, should be an instance of the parent class
(if used). The subsequent arguments are used to set the properties.
- validator
A function taking a single argument, self
, the object
to validate.
The job of a validator is to determine whether the object is valid,
i.e. if the current property values form an allowed combination. The
types of the properties are always automatically validated so the job of
the validator is to verify that the values of individual properties are
ok (i.e. maybe a property should have length 1, or should always be
positive), or that the combination of values of multiple properties is ok.
It is called after construction and whenever any property is set.
The validator should return NULL
if the object is valid. If not, it
should return a character vector where each element describes a single
problem, using @prop_name
to describe where the problem lies.
See validate()
for more details, examples, and how to temporarily
suppress validation when needed.
- .parent, ...
Parent object and named properties used to construct the
object.