5_element_level_formatting: Object Array Formatting

Description Usage Arguments Details Value Examples

Description

Element-level formatting functions for object arrays.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
objtag (...)

## Default S3 method:
objtag(x, ...)
## S3 method for class 'ObjectArray'
objtag(x, ...)
## S3 method for class 'NestMatrix'
objtag(x, ...)
## S3 method for class 'SectMatrix'
objtag(x, ...)
## S3 method for class 'PartMatrix'
objtag(x, ...)
## S3 method for class 'function'
objtag(x, ...)
## S3 method for class 'list'
objtag(x, ...)
## S3 method for class 'matrix'
objtag(x, ...)
## S3 method for class 'data.frame'
objtag(x, ...)

Arguments

x

An object.

...

.

Details

These functions map an object to a single compact string, regardless of the length of the object.

The format method for ObjectArray calls the objtag function for each of its elements.

To format an object of a different class, you need to write an (S3) objtag method for that class.

Value

Each method returns a single compact string.
(i.e. A length-one character vector, that's relatively short).

If you write a new objtag method, it should do the same.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#near-trivial classes
alphabet.1 = function ()
    structure (LETTERS, class="alphabet.1")
alphabet.2 = function ()
    structure (sample (LETTERS), class="alphabet.2")

#near-trivial 2x2 object array
x = ObjectArray (c (2, 2) )
x [[1, 1]] = alphabet.1 ()
x [[2, 1]] = alphabet.1 ()
x [[1, 2]] = alphabet.2 ()
x [[2, 2]] = alphabet.2 ()

#printed with default formatting
x

#objtag methods
objtag.alphabet.1 = function (x)
    paste ("<A1 ", x [1], ":", x [26], ">", sep="")
objtag.alphabet.2 = function (x)
    paste ("<A2 ", x [1], ":", x [26], ">", sep="")

#reprinted with custom formatting
x

vectools documentation built on Jan. 9, 2020, 5:09 p.m.