From ripley at stats.ox.ac.uk  Fri May  9 14:18:31 2003
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri May  9 14:18:42 2003
Subject: [Rd] codes() has been deprecated
Message-ID: <Pine.LNX.4.44.0305091308220.7062-100000@gannet.stats>

We have deprecated codes() in R-devel.  One we started looking into this, 
we found that *all* the uses of codes() in the R sources and probably all 
the uses in CRAN packages were not what we think was intended.

For an ordered factor, codes() is the same as 
unclass/as.vector/as.integer and so was unneeded.

For an unordered factor, codes() does *not* retrieve the internal codes.  
It effectively re-orders the levels into alphabetical order (in the
current locale), forms a factor with those levels and then returns the
internal codes.  This is rarely what is wanted, as if the levels are not
in alphabetical order this is normally reflects some other natural order
and the function should normallyrecognize that.  I normally use unclass()  
to get the internal codes, but as.vector and as.integer work equally well.

R has a codes() replacement function that is also deprecated, and of which 
we can find no uses.

Brian Ripley

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] codes() has been deprecated
Prof Brian Ripley