Learn R Programming

vectools (version 0.2.0)

30_objtag_methods: objtag Methods

Description

Element-level formatting functions for object arrays.

Usage

# S3 method for ObjectArray
objtag(x, …)
# S3 method for NestMatrix
objtag(x, …)
# S3 method for PartMatrix
objtag(x, …)
# S3 method for SectMatrix
objtag(x, …)
# S3 method for MatrixArray
objtag(x, …)

# S3 method for ZERO objtag(x, …)

# S3 method for function objtag(x, …) # S3 method for list objtag(x, …) # S3 method for data.frame objtag(x, …) # S3 method for matrix objtag(x, …)

# S3 method for default objtag(x, …)

Arguments

x

An object.

Ignored.

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.

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.

See Also

format.ObjectArray

Examples

Run this code
# NOT RUN {
#simple classes
alphabet.1 <- function ()
    structure (LETTERS, class="alphabet.1")
alphabet.2 <- function ()
    structure (sample (LETTERS), class="alphabet.2")

#simple 2x2 ObjectArray
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
# }

Run the code above in your browser using DataLab