Intervals-class: Classes "Intervals" and "Intervals_full"

Intervals-classR Documentation

Classes "Intervals" and "Intervals_full"

Description

"Intervals" objects are two-column matrices which represent sets, possibly non-disjoint and in no particular order, of intervals on either the integers or the real line. All intervals in each object have the same endpoint closure pattern. "Intervals_full" objects are similar, but permit interval-by-interval endpoint closure specification.

Objects from the Class

Objects can be created by calls of the form new("Intervals", ...), or better, by using the constructor functions Intervals(...) and Intervals_full(...).

Slots

.Data:

See "Intervals_virtual".

closed:

For "Intervals" objects, a two-element logical vector. For "Intervals_full" objects, a two-column logical matrix with the same dimensions as .Data. If omitted in a new call, the closed slot will be initialized to an object of appropriate type and size, with all entries TRUE. If closed is a vector of length 1, or a vector of length 2 for the "Intervals_full" class, an appropriate object will be made by reusing the supplied values row-wise. See the example below.

type:

See "Intervals_virtual".

Extends

Class "Intervals_virtual", directly.

Class "matrix", by class "Intervals_virtual", distance 2.

Class "array", by class "Intervals_virtual", distance 3.

Class "structure", by class "Intervals_virtual", distance 4.

Class "vector", by class "Intervals_virtual", distance 5, with explicit coerce.

S3 methods

As of R 2.8.1, it still does not seem possible to write S4 methods for rbind or c. To concatenate sets of intervals into a single sets, the S3 methods c.Intervals and c.Intervals_full are provided. While rbind might seem more natural, its S3 dispatch is non-standard and it could not be used. Both methods are documented separately.

S4 methods

[

signature(x = "Intervals")

[

signature(x = "Intervals_full")

[<-

signature(x = "Intervals", i = "ANY", j = "missing", value = "Intervals_virtual")

[<-

signature(x = "Intervals_full", i = "ANY", j = "missing", value = "Intervals_virtual")

adjust_closure

signature(x = "Intervals")

adjust_closure

signature(x = "Intervals_full")

closed<-

signature(x = "Intervals")

closed<-

signature(x = "Intervals_full")

coerce

signature(from = "Intervals", to = "Intervals_full")

coerce

signature(from = "Intervals_full", to = "Intervals")

empty

signature(x = "Intervals")

empty

signature(x = "Intervals_full")

initialize

signature(.Object = "Intervals")

initialize

signature(.Object = "Intervals_full")

size

signature(x = "Intervals")

size

signature(x = "Intervals_full")

Warning

Validity checking takes place when, for example, using the type<- replacement accessor: if one attempts to set type to "Z" but the endpoint matrix contains non-integer values, an error is generated. Because accessors are not used for the endpoint matrix itself, though, it is possible to create invalid "Z" objects by setting endpoints to inappropriate values.

Note

We do not currently permit an integer data type for the endpoints matrix, even when type == "Z", because this creates complications when taking complements – which is most easily handled through the use of -Inf and Inf. This is particularly awkward for objects of class "Intervals", since current endpoint closure settings may not permit inclusion of the minimal/maximal integer. This issue may be addressed, however, in future updates. (We do, however, check that endpoints are congruent to 0 mod 1 when type == "Z".)

When creating object, non-matrix endpoint sources will be converted to a two-column matrix, for convenience. Recycling is supported for the closed slot when creating new objects.

See Also

See "Intervals_virtual".

Examples


# The "Intervals" class

i <- Intervals(
               matrix(
                      c(1,2,  
                        3,5,
                        4,6,
                        8,9
                        ),
                      byrow = TRUE,
                      ncol = 2
               ),
               closed = c( TRUE, TRUE ),
               type = "Z"
               )

# Row subsetting preserves class. Column subsetting causes coercion to
# "matrix" class. 

i
i[1:2,]
i[,1:2]

# Full endpoint control

j <- as( i, "Intervals_full" )
closed(j)[ 3:4, 2 ] <- FALSE
closed(j)[ 4, 1 ] <- FALSE
j

# Rownames may be used

rownames(j) <- c( "apple", "banana", "cherry", "date" )
j

# Assignment preserves class, coercing if necessary

j[2:3] <- i[1:2,]
j


intervals documentation built on July 10, 2023, 2:02 a.m.