[R] write.table(NULL)

Thomas Lumley tlumley at u.washington.edu
Tue Aug 3 23:42:40 CEST 2004


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.

There are quite a lot of functions that treat you harshly when you supply
zero-length input.  This is usually for a similar reason to the one here:
when lapply returns no output the information as to whether it is no
logical values or no vectors or no whatever else gets lost.  It's a good
idea to be cautious about zero-length variables as a programmer.


	-thomas




More information about the R-help mailing list