[Rd] Color mapping for R : col2rgb()

Prof Brian Ripley ripley@stats.ox.ac.uk
Mon, 2 Apr 2001 13:44:24 +0100 (BST)

```On Mon, 2 Apr 2001, Martin Maechler wrote:

>
> This has been an old topic, brought up last year by
> Jens Oehlschlaegel and even before by Ben Bolker and maybe others.
>
> Over the weekend I've finally taken some time,
> and have implemented one new function on the R level,
> basically exposing the underlying C function str2col() [main/graphics.c]
>
> col2rgb() accepts a vector of all three kind of R colors :
>
> 1:n     =  indices into palette()
> name    =  an element of colors()
> #rrggbb =  character with the rgb hex code.
>
> Per color, it returns an integer(3) vector   c(red,green,blue)
> with elements from 0:255.
>
> Currently {in my implementation},
> when
>   r <- col2rgb(col)
> r is a list() of the same length as col, and  r[[j]] = c(red_j, green_j, blue_j)
> e.g.
>     > str(col2rgb(paste("gold", 1:4, sep="")))
>     List of 4
>      \$ : int [1:3] 255 215 0
>      \$ : int [1:3] 238 201 0
>      \$ : int [1:3] 205 173 0
>      \$ : int [1:3] 139 117 0
>     >
>
> This has been the easiest way of a vectorizing implementation.
> Are the strong reasons why, e.g. a matrix should be returned instead ?
> The matrix can `easily' be built by, e.g.
>
>   matrix(c(col2rgb(...) , recursive = TRUE), nrow = 3))
>
> If it is felt that one always wanted this matrix (and dimnames, too),
> it would maybe make sense to compute it in C.

What do you get if you ask for one colour (the most common case?)?
A one-element list seems silly.

Brian

--
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```