david> Full_Name: David M. Potter Version: 0.64.1 OS: solaris 2.6
david> Submission from: (NULL) (12.18.36.220)
david> cm.colors() returns an extra element "1":
Yes, this is a bug
....
david> Why I think it happens
david> The function has an unnecessary right parentheses immediately
david> preceding ", v=1" which causes the "v=1" to be
added to the
david> vector rather than being interpreted as an argument to hsv().
david> > cm.colors
david> function (n)
david> {
david> k <- n%/%2
david> if (2 * k == n) {
david> c(hsv(h = 6/12, s = seq(0.5, 0, length = k + 1)[-k -
david> 1], v = 1), hsv(h = 10/12, s = seq(0, 0.5, length = n -
david> k + 1)[-1]), v = 1)
david> }
david> else {
david> c(hsv(h = 6/12, s = seq(0.5, 0, length = k + 1), v = 1),
david> hsv(h = 10/12, s = seq(0, 0.5, length = n - k)[-1]),
david> v = 1)
david> }
david> }
Correct.
There were more problems :
cm.colors(1) {and cm.colors(0)} both failed as well.
The following seems to be correct in all cases
cm.colors <- function (n)
{
if ((n <- as.integer(n[1])) > 0) {
even.n <- n %% 2 == 0
k <- n%/%2
l1 <- k + 1 - even.n
l2 <- n - k + even.n
c(if(l1 > 0)
hsv(h = 6/12, s= seq(.5, ifelse(even.n,.5/k,0), length = l1), v = 1),
if(l2 > 1)
hsv(h = 10/12, s= seq(0, 0.5, length = l2)[-1], v = 1))
} else character(0)
}
I'll commit it for the R-devel [daily snapshot] and hence 0.65.
Martin Maechler <maechler@stat.math.ethz.ch>
http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum SOL G1 Sonneggstr.33
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1086 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._