From mark at celos.net  Fri Nov 20 11:53:43 2009
From: mark at celos.net (Mark White)
Date: Fri, 20 Nov 2009 10:53:43 +0000
Subject: [Rd] Surprising length() of POSIXlt vector (PR#14073)
In-Reply-To: <65610626-C857-4DDA-BE74-C5CEA8724A38@jhsph.edu>
References: <20091119223013.53B2C282EF57@mail.pubhealth.ku.dk>
	<4143_1258676975_1258676975_C787288D-4F7C-4013-A173-B24A88515225@jhsph.edu>
	<DCE81E14EB74504B971DAD4D2DB0356B032C624F65@crcmail4.BCCRC.CA>
	<65610626-C857-4DDA-BE74-C5CEA8724A38@jhsph.edu>
Message-ID: <20091120105343.GD1848@celos.net>

Benilton Carvalho writes:
> I'm no expert on this, but my understanding is that the choice was
> to stick to the definition.
> 
> The help file for length() [1] says:
> 
> "For vectors (including lists) and factors the length is the number
> of elements."
> 
> The help file for POSIXlt [2] (for example) says:
> 
> "Class ?"POSIXlt"? is a named list of vectors representing (...)"
> 
> and then lists the 9 elements (sec / min / hour / mday / mon / year
> / wday / yday / isdst).
> 
> So, by [1] length of POSIXlt objects is 9, because it "is a named
> list of vectors representing (...)".

Thanks, all.  Yes, I'd already read both, and it's obviously
true that a length() of 9 is correct (as I said up-front).

The difficulty is that some functions -- importantly
including "[" -- already have methods which make POSIXlt
behave like a vector.  The documentation for POSIXlt just
says it's a list of 9 elements: it mentions methods for
addition etc, but AFAICT it doesn't say that subsetting won't
behave is "["'s help says for a list-like object.

In the end, "[" sees a different length to "[[" and "$"
here, so a length.POSIXlt() just shuffles the issue around.

Anyhow, I somehow missed there have been other PRs on this,
including discussion on r-devel of "[" and logical vs physical
length() under PR#10507.  I'm sorry for being repetitive.

Mark <><



[Rd] Surprising length() of POSIXlt vector (PR#14073)
Mark White