From ripley at stats.ox.ac.uk  Tue Sep  7 00:30:36 2004
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue Sep  7 00:30:45 2004
Subject: [Rd] Glitch involving difftime and data frame
In-Reply-To: <x2llfn2gb2.fsf@biostat.ku.dk>
Message-ID: <Pine.LNX.4.44.0409062326140.27999-100000@gannet.stats>

On 7 Sep 2004, Peter Dalgaard wrote:

> This looks unintentional:

Not so.

> > d <- as.Date("2004-09-07")
> > dd <- as.Date("2004-10-04")
> > data.frame(d,dd,dd-d)
> Error in as.data.frame.default(x[[i]], optional = TRUE) :
>         can't coerce difftime into a data.frame
> > F <- data.frame(d,dd)
> > F$foo <- dd-d
> > cbind(F,dd-d)
> Error in as.data.frame.default(x[[i]], optional = TRUE) :
>         can't coerce difftime into a data.frame
> 
> Basically, the issue is that as.data.frame on a classed object expects
> to find a method and there isn't any for difftime...

Difftime depends crucially on attributes on the vector.  I wasn't 
confident that they would be preserved as needed (and I think I had a 
problem example).  Since then we have fixed a lot of the subsetting 
methods, but even so I am not 100% confident.

-- 
Brian D. Ripley,                  ripley@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


[Rd] Glitch involving difftime and data frame
Prof Brian Ripley