Learn R Programming

set6 (version 0.1.1)

Tuple: Mathematical Tuple

Description

A general Tuple object for mathematical tuples, inheriting from Set.

Value

R6 object of class Tuple inheriting from Set.

Constructor

Tuple$new(..., universe = UniversalSet$new())

Constructor Arguments

Argument Type Details
... ANY Elements in the tuple.
universe Set Universe that the Tuple lives in, default UniversalSet.
elements list Alternative constructor that may be more efficienct if passing objects of multiple classes.
class character Optional string naming a class that if supplied gives the set the typed property.

Constructor Details

Tuples are constructed by elements of any types (including R6 classes). The universe argument is useful for taking the absolute complement of the Tuple. If a universe isn't given then UniversalSet is assumed. If the class argument is non-NULL, then all elements will be coerced to the given class in construction, and if elements of a different class are added these will either be rejected or coerced.

Public Fields

Field Link

class class elements elements length length lower lower upper upper max max min min range range properties properties traits traits type type

Public Methods

Comparison Methods Link contains(x, all = FALSE, bound = NULL) contains equals(x, all = FALSE) equals isSubset(x, proper = FALSE, all = FALSE) isSubset Representation Methods Link strprint(n = 2) strprint print(n = 2) print summary(n = 2) summary

Details

Tuples are similar to sets, except that they drop the constraint for elements to be unique, and ordering in a tuple does matter. Tuples are useful for methods including contains that may require non-unique elements. They are also the return type of the product of sets. See examples.

See Also

Other sets: ConditionalSet, FuzzySet, FuzzyTuple, Interval, Set, UniversalSet

Examples

Run this code
# NOT RUN {
# Tuple of integers
Tuple$new(1:5)

# Tuple of multiple types
Tuple$new("a", 5, Set$new(1), Tuple$new(2))

# Each Tuple has properties and traits
t = Tuple$new(1,2,3)
t$traits
t$properties

# Elements can be duplicated
Tuple$new(2, 2) != Tuple$new(2)

# Ordering does matter
Tuple$new(1, 2) != Tuple$new(2, 1)

# }

Run the code above in your browser using DataLab