From p.dalgaard at biostat.ku.dk  Mon Jul 31 14:43:06 2006
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 31 Jul 2006 14:43:06 +0200
Subject: [Rd] Warning when indexing data.frame with FALSE
In-Reply-To: <Pine.LNX.4.64.0607311253030.21136@gannet.stats.ox.ac.uk>
References: <f8e6ff050607310441v1cd40ae0n6fb479cbd5a763a0@mail.gmail.com>
	<f8e6ff050607310442h16778689va0d70206042311e8@mail.gmail.com>
	<Pine.LNX.4.64.0607311253030.21136@gannet.stats.ox.ac.uk>
Message-ID: <x2hd0yq71h.fsf@viggo.kubism.ku.dk>

Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

> On Mon, 31 Jul 2006, hadley wickham wrote:
> 
> > Sorry, a better example is:
> > 
> > > data.frame(a=1)[FALSE]
> > NULL data frame with 1 rows
> > > data.frame(a=1)[NULL]
> > NULL data frame with 1 rows
> > 
> > vs
> > 
> > > data.frame()[FALSE]
> > Warning in is.na(nm) : is.na() applied to non-(list or vector)
> > NULL data frame with 0 rows
> > > data.frame()[NULL]
> > Warning in is.na(nm) : is.na() applied to non-(list or vector)
> > NULL data frame with 0 rows
> 
> It's reasonable:
> 
> > names(data.frame())
> NULL
> 
> which is a problem as data frames are supposed to have names.
> So the bug is in data.frame.

To wit:

> d <- data.frame()
> names(d) <- character(0)
> d[FALSE]
NULL data frame with 0 rows
> d[NULL]
NULL data frame with 0 rows



-- 
   O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



[Rd] Warning when indexing data.frame with FALSE
Peter Dalgaard