Learn R Programming

methods (version 3.6.2)

nonStructure-class: A non-structure S4 Class for basic types

Description

S4 classes that are defined to extend one of the basic vector classes should contain the class '>structure if they behave like structures; that is, if they should retain their class behavior under math functions or operators, so long as their length is unchanged. On the other hand, if their class depends on the values in the object, not just its structure, then they should lose that class under any such transformations. In the latter case, they should be defined to contain nonStructure.

If neither of these strategies applies, the class likely needs some methods of its own for Ops, Math, and/or other generic functions. What is not usually a good idea is to allow such computations to drop down to the default, base code. This is inconsistent with most definitions of such classes.

Arguments

Methods

Methods are defined for operators and math functions (groups Ops, Math and Math2). In all cases the result is an ordinary vector of the appropriate type.

References

Chambers, John M. (2008) Software for Data Analysis: Programming with R Springer.

See Also

'>structure

Examples

Run this code
# NOT RUN {
setClass("NumericNotStructure", contains = c("numeric","nonStructure"))
xx <- new("NumericNotStructure", 1:10)
xx + 1 # vector
log(xx) # vector
sample(xx) # vector
# }

Run the code above in your browser using DataLab