]> git.donarmstrong.com Git - ape.git/blob - R/alex.R
various bug fixes
[ape.git] / R / alex.R
1 ## alex.R (2012-03-27)
2
3 ##   Alignment Explorer With Multiple Devices
4
5 ## Copyright 2012 Emmanuel Paradis
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 alex <- function(x, ...)
11 {
12     n <- nrow(x)
13     s <- ncol(x)
14     devmain <- dev.cur()
15     on.exit(dev.set(devmain))
16     NEW <- TRUE
17     cat("Click on two opposite corners of the zone you want to zoom-in.
18 Right-click to exit.\n")
19     repeat {
20         xy <- locator(2)
21         if (is.null(xy)) break
22         xy <- lapply(xy, function(x) sort(round(x)))
23         i1 <- xy$y[1L]; i2 <- xy$y[2L]
24         j1 <- xy$x[1L]; j2 <- xy$x[2L]
25         if (i1 > n || j1 > s) cat("Try again!\n") else {
26             if (i1 <= 0) i1 <- 1L
27             if (j1 <= 0) j1 <- 1L
28             if (i2 > n) i2 <- n
29             if (j2 > s) j2 <- s
30             if (NEW) {
31                 dev.new()
32                 devsub <- dev.cur()
33                 NEW <- FALSE
34             } else dev.set(devsub)
35             image(x[i1:i2, j1:j2], xaxt = "n", ...)
36             atx <- axTicks(1)
37             axis(1, atx, labels = (j1:j2)[atx])
38             title(sub = paste("From", sQuote(deparse(substitute(x)))))
39             dev.set(devmain)
40         }
41     }
42 }