Skip to content
Prev 9497 / 63424 Next

codes() has been deprecated

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