intervals (version 0.15.1)

Intervals-class: 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.

Arguments

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")

% \item{\code{[}:}{ % When used to subset rows, class is preserved; when used to subset % columns, the \code{closed} and \code{type} slots are discarded and % an appropriately subset version of \code{.Data} is returned. See % example below. % } % % \item{\code{closed<-}:}{ % Replacement accessor for \code{closed} slot. See the example % below. See description of the \code{closed} slot above for details % on how one- or two-element logical vectors are interpreted. % } % % \item{\code{coerce}:}{ % Coercion methods are provided for converting back and forth % between \code{"Intervals"} and \code{"Intervals_full"} % objects. See example below. An error will be generated when % attemption to down-class a \code{"Intervals_full"} object which % does not have the same closure settings for every interval. % % A coercion method is also provided for pretty character strings. % }

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.

See Also

See "'>Intervals_virtual".

Examples

Run this code
# NOT RUN {
# 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

# }

Run the code above in your browser using DataCamp Workspace