On 07/06/2013 18:59, Bryan Hanson wrote:
Hello Core Folk.
This is the R-devel list. Bug reports/enhancement suggestions should go to bugs.r-project.org.
Quite by accident I discovered today that col2rgb, when fed factors, acts on the integer representation of those factors: td <- as.factor(rainbow(5)) # not how I discovered the issue! td res <- col2rgb(td) res # but col2rgb("#FF0000FF") # this is td[1] but does not produce the same answer res[,1] # moreover as.integer(td) col2rgb(5) # the integer value of the first level # and this is res[,1] which by the way is palette()[5], aka "cyan" ?col2rgb says: col vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. Non-numeric values are coerced to character. So in the example the factor is being taken as its integer representation, and finding an integer as the input value, col2rgb goes to palette(). Perhaps this is a nuance that belongs in the documentation?
It has been like that since at least R 2.0.0. I'll rephrase the help and change to coercion to character.
Thanks, Bryan *********** Bryan Hanson Professor of Chemistry & Biochemistry DePauw University ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
-- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel