setS3: Set and ordered Set

SetS3R Documentation

Set and ordered Set

Description

The Set is considered and implemented as a specialized Container, that is, Set elements are always unique. It provides typical set operations such as union and intersect.

Usage

setnew(..., .ordered = FALSE)

as.set(x)

as.orderedset(x)

is.set(x)

is.orderedset(x)

Arguments

...

initial elements put into the Set.

.ordered

logical if TRUE all elements in the Set will be ordered.

x

R object of ANY type for as.set() and is.set() or of class Set for the S3 methods.

Details

Methods that alter Set objects usually come in two versions providing either copy or reference semantics where the latter start with 'ref_' to note the reference semantic, for example, add() and ref_add().

  • setnew(...) initializes and returns a Set() object.

  • as.set(x) coerces x to a set.

  • as.orderedset(x) coerces x to an ordered set.

  • is.set(x) returns TRUE if x is of class Set and FALSE otherwise.

  • is.orderedset(x) returns TRUE if x is of class OrderedSet and FALSE otherwise.

  • x & y performs the set intersection of x and y

  • x | y performs the set union of x and y

See Also

See container() for all inherited methods. For the full class documentation see Set and it's superclass Container.

Examples

s = setnew(1, b = NA, 1:3, c = container("a", 1))
is.set(s)
print(s)
length(s)
names(s)
as.list(s)
unpack(s)   # flatten recursively similar to unlist

so = setnew(2, 1, .ordered = TRUE)
print(so)
add(so, 0)
# Math
s = setnew(5:3, 1, 2)
s
abs(s)
cumsum(s)
round(s)
exp(s)

# Summary
range(s)
min(s)
max(s)

s1 = setnew(1, 1:2)
s2 = setnew(2, 1:2)
s1 + s2     # same as s1 | s2 or c(c1, s2)
s2 + s1     # same

s1 - s2
s2 - s1

s1 = setnew(1, b = 2)
s2 = setnew(1, b = 4)
s1 & s2     # {1}

s1 | s2     # {1, b = 2, b = 4}


rpahl/container documentation built on Nov. 10, 2023, 6:31 p.m.