new_unitted_class: Define a custom subclass of 'unitted'

Description Usage Arguments Details Examples

Description

There is already a unitted class defined for each of the basic classes (numeric, logical, character, ...), many of the most common S3 data structures (factor, Date, POSIXct), and both lists and data.frames. And for the most part, only the numeric types will make sense as unitted types. However, there may still be cases where you need yet another class for yet another data type. new_unitted_class helps you define such a class.

Usage

1
new_unitted_class(superclass.name, overwrite = FALSE)

Arguments

superclass.name

The character name of the S4 class that will form the core of the new unitted class. The new class will have the name "unitted_[superclass.name]".

overwrite

Logical. If TRUE, the new setClass call will be executed even if the same superclass.name has already been defined during this session.

Details

Your new class will have to be S4; I have found no way to circumvent this requirement. However, a close S4 counterpart can be constructed for nearly any S3 class. See the examples.

Your new class should also have a .Data part to it, because only those computations that apply to the .Data part will affect and be affected by the units. The default behavior of unitted subclasses expects a single unitbundle in the units slot, which means a single set of units per object. Data.frames and lists are the notable exceptions.

It is also important to distinguish between S3/S4 classes and S3/S4 methods. Even though you must use an S4 class, you may use any combination of S3 and S4 methods; all of these will be correctly dispatched on objects inheriting from the unitted class, providing that you define your classes correctly and that the dispatch behavior you want is within the abilities of the particular dispatch system (S3 or s4).

Examples

1
# only works during package build, at least at the moment

appling/unitted documentation built on May 10, 2019, 12:44 p.m.