hadley/lubridate — Issue #96: length() on periods
Author: kenahoo
Created: 2011-11-04 13:49:06+00:00
State: open

One source of trouble with `period` objects is that `length()` always returns 6, since it's based on a `data.frame` with 6 columns. Contrast this with `duration` objects, for which `length()` returns the number of durations indicated.

> length(dhours(1:9))
[1] 9
> length(hours(1:9))
[1] 6

Unfortunately it's not possible to just implement a `length.period` method, because then all kinds of mayhem happens when various other `period` methods (and probably various other R functions outside lubridate) use the `length()` method and expect it to return the number of columns (even though they should probably use `ncol` instead).

I'm wondering what could be done about this - the obvious thing would be to rotate the internal data frame 90 degrees, but since the `seconds` component can be non-integer, that means *all* components would potentially turn into floats.

Any other thoughts? It ends up impeding the person who wants to use periods in various ways - for example it can't usefully be an argument to `lapply` and friends.