[Rd] col2rgb, factors & documentation
hanson at depauw.edu
Fri Jun 7 19:59:52 CEST 2013
Hello Core Folk.
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!
res <- col2rgb(td)
col2rgb("#FF0000FF") # this is td but does not produce the same answer
col2rgb(5) # the integer value of the first level
# and this is res[,1] which by the way is palette(), aka "cyan"
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?
Professor of Chemistry & Biochemistry
More information about the R-devel