[R] write.table(NULL)

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 3 23:55:37 CEST 2004


On Tue, 3 Aug 2004, Thomas Lumley wrote:

> On Tue, 3 Aug 2004, Jack Tanner wrote:
> 
> >  > write.table(NULL)
> > Error in which(unlist(lapply(x, function(x) is.character(x) ||
> > is.factor(x)))) : argument to "which" is not logical
> >
> > Is this correct behavior? It seems harsh to abort an entire run just
> > because one of the tables you generated happened to be NULL.
> >
> 
> Well, yes, in a perfect world write.table(NULL) would just write no
> output.  It's arguably even a bug, or at least the fact that the same
> thing happens with a zero-length data frame is arguably a bug. I'll fix
> it.

It's zero-column cases it gets in trouble with: zero-row cases are handled 
correctly AFAICS.  Depends what `zero-length' means.

We should change it, although what is the right output is less clear to
me. You can have zero-columns and non-zero rows and with row names.
Compare

> hills[FALSE]
NULL data frame with 35 rows

with
> as.matrix(hills[FALSE])

(a column of rownames).

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