From brahm at alum.mit.edu  Wed Jul 21 01:36:16 2004
From: brahm at alum.mit.edu (David Brahm)
Date: Wed Jul 21 01:36:34 2004
Subject: [Rd] as.matrix.data.frame() warning for POSIXt columns
Message-ID: <16637.44144.896582.143029@arbres1a.fmr.com>

as.matrix.data.frame() issues a spurious warning for POSIXt columns in R-1.9.1:

R> x <- data.frame(date=as.POSIXct("2004-07-20"))
R> as.matrix(x)
     date        
   1 "2004-07-20"
   Warning message: longer object length is not a multiple of shorter
   object length in: cl == c("Date", "POSIXct", "POSIXlt") 

This bug also affects write.table(x), which uses as.matrix.data.frame(x).  It
arises because the function is comparing the column class, which is a vector of
length 2, to a vector of possible values of length 3, using == instead of %in%.

It was discussed in R-help on May 24,2004 by Don MacQueen <macq@llnl.gov> and
Brian Ripley <ripley@stats.ox.ac.uk>, where Brian Ripley said:
  BDR> The Warning is wrong, though, and will be fixed. 
but it is still there as of R-patched_2004-07-20.

The following patch to R-1.9.1/src/library/base/R/dataframe.R ought to do it:
agate> diff dataframe.R dataframe.new.R 
1044c1044
<              any(cl == c("Date", "POSIXct", "POSIXlt"))))
---
>              any(cl %in% c("Date", "POSIXct", "POSIXlt"))))

-- 
                              -- David Brahm (brahm@alum.mit.edu)


[Rd] as.matrix.data.frame() warning for POSIXt columns
David Brahm