\HeaderA{Ranges-comparison}{Ranges comparison}{Ranges.Rdash.comparison}
\aliasA{"!=}{Ranges-comparison}{"!=}
\aliasA{"!=,Ranges,Ranges-method}{Ranges-comparison}{"!=,Ranges,Ranges.Rdash.method}
\aliasA{<}{Ranges-comparison}{<}
\aliasA{<,Ranges,Ranges-method}{Ranges-comparison}{<,Ranges,Ranges.Rdash.method}
\aliasA{<=}{Ranges-comparison}{<=}
\aliasA{<=,Ranges,Ranges-method}{Ranges-comparison}{<=,Ranges,Ranges.Rdash.method}
\aliasA{==}{Ranges-comparison}{==}
\aliasA{==,Ranges,Ranges-method}{Ranges-comparison}{==,Ranges,Ranges.Rdash.method}
\aliasA{>}{Ranges-comparison}{>}
\aliasA{>,Ranges,Ranges-method}{Ranges-comparison}{>,Ranges,Ranges.Rdash.method}
\aliasA{>=}{Ranges-comparison}{>=}
\aliasA{>=,Ranges,Ranges-method}{Ranges-comparison}{>=,Ranges,Ranges.Rdash.method}
\aliasA{duplicated,Ranges-method}{Ranges-comparison}{duplicated,Ranges.Rdash.method}
\aliasA{order}{Ranges-comparison}{order}
\aliasA{order,Ranges-method}{Ranges-comparison}{order,Ranges.Rdash.method}
\aliasA{rank,Ranges-method}{Ranges-comparison}{rank,Ranges.Rdash.method}
\aliasA{sort,Ranges-method}{Ranges-comparison}{sort,Ranges.Rdash.method}
\aliasA{unique,Ranges-method}{Ranges-comparison}{unique,Ranges.Rdash.method}
\keyword{methods}{Ranges-comparison}
\begin{Description}\relax
Equality and ordering of ranges, and related methods.
\end{Description}
\begin{Usage}
\begin{verbatim}
  ## ==== Equality and related methods ====
  ## --------------------------------------

  x == y
  x != y

  ## S4 method for signature 'Ranges':
  duplicated(x, incomparables=FALSE, fromLast=FALSE, ...)

  ## S4 method for signature 'Ranges':
  unique(x, incomparables=FALSE, fromLast=FALSE, ...)

  ## ==== Ordering and related methods ====
  ## --------------------------------------

  x <= y
  x >= y
  x < y
  x > y

  ## S4 method for signature 'Ranges':
  order(..., na.last=TRUE, decreasing=FALSE)

  ## S4 method for signature 'Ranges':
  sort(x, decreasing=FALSE, ...)

  ## S4 method for signature 'Ranges':
  rank(x, na.last=TRUE, ties.method=c("average", "first", "random", "max", "min"))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x,y}] A \LinkA{Ranges}{Ranges} object.

\item[\code{incomparables}] Must be \code{FALSE}.

\item[\code{fromLast}] \code{TRUE} or \code{FALSE}.

\item[\code{...}] \LinkA{Ranges}{Ranges} objects for \code{order}.

\item[\code{na.last}] Ignored.

\item[\code{decreasing}] \code{TRUE} or \code{FALSE}.

\item[\code{ties.method}] A character string specifying how ties are treated. Only \code{"first"}
is supported for now.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Two ranges are considered equal iff they share the same start and width.
Note that with this definition, 2 empty ranges are generally
not equal (they need to share the same start to be considered equal).
This means that, when it comes to comparing ranges, an empty range is
interpreted as a position between its end and start. For example, a
typical usecase is comparison of insertion points defined along a string
(like a DNA sequence) and represented as empty ranges.

Ranges are ordered by starting position first, and then by width.
This way, the space of ranges is totally ordered.
The \code{order}, \code{sort} and \code{rank} methods for \LinkA{Ranges}{Ranges}
objects are consistent with this order.

\describe{
\item[] \code{duplicated(x)}:
Determines which elements of \code{x} are equal to elements
with smaller subscripts, and returns a logical vector indicating
which elements are duplicates.
It is semantically equivalent to \code{duplicated(as.data.frame(x))}.
See \code{\LinkA{duplicated}{duplicated}} in the base package for more details.

\item[] \code{unique(x)}:
Removes duplicate ranges from \code{x}.
See \code{\LinkA{unique}{unique}} in the base package for more details.

\item[] \code{order(...)}:
Returns a permutation which rearranges its first argument (a \LinkA{Ranges}{Ranges}
object) into ascending order, breaking ties by further arguments (also
\LinkA{Ranges}{Ranges} objects).
See \code{\LinkA{order}{order}} in the base package for more details.

\item[] \code{sort(x)}:
Sorts \code{x}.
See \code{\LinkA{sort}{sort}} in the base package for more details.

\item[] \code{rank(x, na.last=TRUE, ties.method=c("average", "first", "random", "max", "min"))}:
Returns the sample ranks of the ranges in \code{x}.
See \code{\LinkA{rank}{rank}} in the base package for more details.

}
\end{Details}
\begin{SeeAlso}\relax
\LinkA{Ranges-class}{Ranges.Rdash.class},
\LinkA{IRanges-class}{IRanges.Rdash.class},
\code{\LinkA{duplicated}{duplicated}},
\code{\LinkA{unique}{unique}},
\code{\LinkA{order}{order}},
\code{\LinkA{sort}{sort}},
\code{\LinkA{rank}{rank}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  x <- IRanges(start=c(20L, 8L, 20L, 22L, 25L, 20L, 22L, 22L),
               width=c( 4L, 0L, 11L,  5L,  0L,  9L,  5L,  0L))
  x
  which(width(x) == 0)  # 3 empty ranges
  x[2] == x[2]  # TRUE
  x[2] == x[5]  # FALSE
  x == x[4]
  duplicated(x)
  unique(x)
  x >= x[3]
  order(x)
  sort(x)
  rank(x, ties.method="first")
\end{ExampleCode}
\end{Examples}

