[R] column names in matrix vs. data frame in R 1.8

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Feb 17 17:40:27 CET 2004


On Tue, 17 Feb 2004 White.Denis at epamail.epa.gov wrote:

> 
> 
> 
> 
> ...
> 
> > > Ok, I'll regard it as an inconsistency that the conversion of
> dimnames
> > > to data frame column names changes reserved words to legitimate
> names
> > > but direct assignment doesn't.
> >
> > It's not inconsistent.  data.frame has an argument `check.names' to
> > control the behaviour on *creating* a data frame, and you didn't
> consult
> > the documentation.  Using the function names<- on the list underlying
> the
> > data frame does not know or care it is applied to a data frame.
> 
> After thinking about this, I guess I wonder why names<- shouldn't have
> the argument 'check.names' and/or check the class of its main argument.
> Why offer protection in one situation and not another?

I don't think you got the point.  names<- applies to a generic vector aka 
list, and the protection applies when generating data frames, not lists.
It really is a feature of data frames, not of lists and not of matrices.

More pedantically,

> get("names<-")
function (x, value) 
UseMethod("names<-")
<environment: namespace:base>

so there is no possibility of an extra argument for names<-, even if a 
data-frame method were added.

-- 
Brian D. Ripley,                  ripley at 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




More information about the R-help mailing list