| 1 |
\name{inv.seq} |
| 2 |
\alias{inv.seq} |
| 3 |
\title{Inverse seq() -- Short Expression for Index Vector} |
| 4 |
\description{ |
| 5 |
Compute a short expression for a given integer vector, typically |
| 6 |
an index, that can be expressed shortly, using \code{\link{:}} etc. |
| 7 |
} |
| 8 |
\usage{ |
| 9 |
inv.seq(i) |
| 10 |
} |
| 11 |
\arguments{ |
| 12 |
\item{i}{vector of (usually increasing) integers.} |
| 13 |
} |
| 14 |
%%\details{ |
| 15 |
%%} |
| 16 |
\value{ |
| 17 |
a \code{\link{call}} (\dQuote{the inside of an |
| 18 |
\code{\link{expression}}}) to be \code{\link{eval}()}ed to |
| 19 |
return the original \code{i}. |
| 20 |
} |
| 21 |
\author{Martin Maechler, October 1995; more elegant implementation from Tony Plate.} |
| 22 |
\seealso{\code{\link{rle}} for another kind of integer vector coding.} |
| 23 |
\examples{ |
| 24 |
(rr <- inv.seq(i1 <- c(3:12, 20:24, 27, 30:33))) |
| 25 |
eval(rr) |
| 26 |
stopifnot(eval(rr) == i1) |
| 27 |
|
| 28 |
e2 <- expression(c(20:13, 3:12, -1:-4, 27, 30:31)) |
| 29 |
(i2 <- eval(e2)) |
| 30 |
(r2 <- inv.seq(i2)) |
| 31 |
stopifnot(all.equal(r2, e2[[1]])) |
| 32 |
|
| 33 |
## Had {mapply()} bug in this example: |
| 34 |
ii <- c(1:3, 6:9, 11:16) |
| 35 |
stopifnot(identical(ii, eval(inv.seq(ii)))) |
| 36 |
} |
| 37 |
\keyword{arith} |
| 38 |
\keyword{utilities} |