Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should `month()` behave when given an integer vector? #887

Closed
jameslairdsmith opened this issue Apr 25, 2020 · 1 comment
Closed

How should `month()` behave when given an integer vector? #887

jameslairdsmith opened this issue Apr 25, 2020 · 1 comment

Comments

@jameslairdsmith
Copy link

@jameslairdsmith jameslairdsmith commented Apr 25, 2020

month() has a (currently undocumented) feature where it can convert a numeric vector into an ordered factor of month names or abbreviations. If given invalid input, however, it produces undesirable results. If label = T then the input values that are not integers from 1 to 12 return <NA> instead triggering an error. This might make someone think the value in question was missing rather than invalid. Not sure why anyone would do this, but if label = F however, then the input values are just returned as output.

Might be worth having a separate function to perform this operation, perhaps something like fct_month()?

library(lubridate, warn.conflicts = F)

month(1:3, label = T)
#> [1] Jan Feb Mar
#> 12 Levels: Jan < Feb < Mar < Apr < May < Jun < Jul < Aug < Sep < ... < Dec
month(0:3, label = T)
#> [1] <NA> Jan  Feb  Mar 
#> 12 Levels: Jan < Feb < Mar < Apr < May < Jun < Jul < Aug < Sep < ... < Dec
month(1:3)
#> [1] 1 2 3
month(0:3)
#> [1] 0 1 2 3

Created on 2020-04-25 by the reprex package (v0.3.0)

@vspinu
Copy link
Member

@vspinu vspinu commented Apr 30, 2020

You are right. Let's throw an error for invalid months.

@vspinu vspinu closed this in 133b6f5 Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.