From jhallman at frb.gov  Mon Dec 17 16:13:07 2007
From: jhallman at frb.gov (Jeffrey J. Hallman)
Date: Mon, 17 Dec 2007 10:13:07 -0500
Subject: [Rd] Wrong length of POSIXt vectors (PR#10507)
References: <20071211112025.811162834156@mail.pubhealth.ku.dk>
	<475FF376.8080806@stats.uwo.ca> <47618124.7060504@acm.org>
	<47618A54.3060900@stats.uwo.ca> <4762EE76.9070401@acm.org>
	<18276.21133.818619.889393@ada-stat.math.ethz.ch>
	<47653917.9090905@stats.uwo.ca>
Message-ID: <xmrejdlxsl8.fsf@mralx1.rsma.frb.gov>

Duncan Murdoch <murdoch at stats.uwo.ca> writes:

> One reason I don't want to work on this is because the appropriate 
> action depends on what "length(x)" is intended to mean.  Currently for 
> POSIXlt objects, it gives the physical length of the underlying basic 
> type (the list).  This is the same behaviour as we have for matrices, 
> data frames and every other object without a specific length method, so 
> it's not outrageous.
>
> The proposed change is to have it return the logical length of the 
> object, which also seems quite reasonable.  I don't think matrices and 
> data frames have a "logical length", so there would be no contradiction 
> in those examples.  The thing that worries me is that there are probably 
> objects in packages where both logical length and physical length make 
> sense but are different.  I don't have any expectation that length(x) on 
> those currently is consistent in which type of value it returns.
>
> If we were to decide that "length(x)" *always* meant logical length, 
> then we would have a problem:  matrices and data frames don't have a 
> logical length, so we shouldn't be getting an answer there.  Changing 
> length(x) for those is not acceptable.
>
> On the other hand, if we decide that "length(x)" *always* means physical 
> length, we don't need to do anything to the POSIXlt or matrices or data 
> frames, but there may well be other kinds of objects out there that 
> violate this rule.
>
> We could leave the meaning of length(x) ambiguous.  If you want to know 
> what it does for a POSIXlt object, you need to read the documentation or 
> look at the source code.  As a policy, this isn't particularly 
> appealing, but I could probably live with it if someone else did the 
> research and showed that current usage is ambiguous.

Physical length and logical length are, as you say, two different things.  So
why not two functions?  Keep length() for physical length, as it is now, and
maybe Length() for logical length.  The latter could be defined as

Length <- function(x, ...) UseMethod("Length")

Length.default <- function(x, ...) length(x)

and then add methods for classes that want something else.

-- 
Jeff



[Rd] Wrong length of POSIXt vectors (PR#10507)
Jeffrey J. Hallman