tidyverse / hms

A simple class for storing time-of-day values
https://hms.tidyverse.org/
Other
138 stars 25 forks source link

When passing lists to hms, if you pass hour, minutes, seconds, and days it returns a single value #49

Closed 808sAndBR closed 6 years ago

808sAndBR commented 6 years ago

When passing lists to just hour, minutes, and seconds (or any individually) it returns a vector of the same length:

> hms(1:10,1:10,1:10)
01:01:01
02:02:02
03:03:03
04:04:04
05:05:05
06:06:06
07:07:07
08:08:08
09:09:09
10:10:10

But if you also include a list of days, it will return one number:

> hms(1:10,1:10,1:10,1:10)
1375:55:55

In a dataframe it does behaves similarly, filling the column with all the same number:

> foo <- data.frame(sec  = 1:10,
                    min  = 1:10,
                    hour = 1:10,
                    day  = 1:10)

> foo %>% dplyr::mutate(hms(sec,min,hour,day))
    sec min hour day hms(sec, min, hour, day)
1    1   1    1   1               1375:55:55
2    2   2    2   2               1375:55:55
3    3   3    3   3               1375:55:55
4    4   4    4   4               1375:55:55
5    5   5    5   5               1375:55:55
6    6   6    6   6               1375:55:55
7    7   7    7   7               1375:55:55
8    8   8    8   8               1375:55:55
9    9   9    9   9               1375:55:55
10  10  10   10  10               1375:55:55

I would have expected to receive a vector of equal length when also passing days (or to get an error telling me not to do that, similarly to if you try to pass just seconds and days).

I'm not sure how often this use case would come up. I came across it while trying to make hms vectors to test with in another project so I am perhaps outside of your normal scope. Wanted to give you a heads up though in case it's helpful.

Thanks for the great package!

krlmlr commented 6 years ago

Thanks for reporting!

github-actions[bot] commented 3 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.