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

David Brahm brahm at alum.mit.edu
Wed Jul 21 01:36:16 CEST 2004


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 at llnl.gov> and
Brian Ripley <ripley at 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 at alum.mit.edu)



More information about the R-devel mailing list