Closed arnaud-feldmann closed 2 years ago
you're spot on. without delimiter, an error should be expected. Will fix this soon.
actually, users can supply any additional formats in format
argument in yearmonth()
. I should have documented format
argument. I can throw a warning if all numbers without delimiter.
library(tsibble)
#>
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, union
yearmonth("202002", format = "%Y%m")
#> <yearmonth[1]>
#> [1] "2020 Feb"
yearmonth("202012", format = "%Y%m")
#> <yearmonth[1]>
#> [1] "2020 Dec"
Created on 2021-10-18 by the reprex package (v2.0.1)
Now:
library(tsibble)
#>
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, union
yearmonth(c("202012", "202002"))
#> Warning: `yearmonth()` may yield unexpected results.
#> ℹ Please use arg `format` to supply formats.
#> <yearmonth[2]>
#> [1] "2020 Feb" "2020 Feb"
yearmonth(c("202012", "202002"), format = "%Y%m")
#> <yearmonth[2]>
#> [1] "2020 Dec" "2020 Feb"
Created on 2021-10-18 by the reprex package (v2.0.1)
Thanks :D warning is ok I think @earowang, and documenting the format arg is even better ! I noticed that because somebody "I know" made a silly mistake 😇
There is a potential confusion with the usage of the yearmonth function on number strings without a delimiter
gives the expected result. But
doesn't work.
I think either yearmonth should refuse this format and throwing an error, or stick with a default delimiter-less format (while maybe throwing a warning or a message). The expected behaviour, I think, doesn't involve interpreting a number as a delimiter.
Note that this can be a bit dangerous otherwise, as making some correct calcs on the begining of the year can make you think the package is ok with this format