lubridate icon indicating copy to clipboard operation
lubridate copied to clipboard

the function `ymd_hms()` is aborting after 150 `NA`

Open VincentGuyader opened this issue 2 years ago • 1 comments

Dear lubridate maintainers,

if the first 150 "guessing" return NA then all following guessing will return NA which is annoying when it happens :)

library(lubridate)
#> 
#> Attachement du package : 'lubridate'
#> Les objets suivants sont masqués depuis 'package:base':
#> 
#>     date, intersect, setdiff, union
library(magrittr)
#> Warning: le package 'magrittr' a été compilé avec la version R 4.1.3
ymd_hms(c(rep("NAT00:00:00",150),"2022-11-01T00:00:00"))%>% rev() %>%.[1]
#> Warning: 150 failed to parse.
#> [1] "2022-11-01 UTC"
ymd_hms(c(rep("NAT00:00:00",151),"2022-11-01T00:00:00"))%>% rev() %>%.[1]
#> Warning: All formats failed to parse. No formats found.
#> [1] NA

Created on 2022-08-29 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value
#>  version  R version 4.1.2 (2021-11-01)
#>  os       Windows 10 x64 (build 19044)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  French_France.1252
#>  ctype    French_France.1252
#>  tz       Europe/Paris
#>  date     2022-08-29
#>  pandoc   2.18 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date (UTC) lib source
#>  cli           3.3.0   2022-04-25 [1] CRAN (R 4.1.3)
#>  digest        0.6.29  2021-12-01 [1] CRAN (R 4.1.2)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate      0.15    2022-02-18 [1] CRAN (R 4.1.3)
#>  fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.0)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
#>  fs            1.5.2   2021-12-08 [1] CRAN (R 4.1.2)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.1.3)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.1.3)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.2)
#>  knitr         1.39    2022-04-26 [1] CRAN (R 4.1.3)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.2)
#>  lubridate   * 1.8.0   2021-10-07 [1] CRAN (R 4.1.2)
#>  magrittr    * 2.0.3   2022-03-30 [1] CRAN (R 4.1.3)
#>  pillar        1.8.0   2022-07-18 [1] CRAN (R 4.1.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
#>  R.cache       0.15.0  2021-04-30 [1] CRAN (R 4.1.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.1.3)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.1.3)
#>  R.utils       2.12.0  2022-06-28 [1] CRAN (R 4.1.3)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.2)
#>  rlang         1.0.4   2022-07-12 [1] CRAN (R 4.1.3)
#>  rmarkdown     2.14    2022-04-25 [1] CRAN (R 4.1.3)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.1.2)
#>  stringi       1.7.6   2021-11-29 [1] CRAN (R 4.1.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
#>  styler        1.7.0   2022-03-13 [1] CRAN (R 4.1.3)
#>  tibble        3.1.6   2021-11-07 [1] CRAN (R 4.1.2)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.2)
#>  vctrs         0.4.1   2022-04-13 [1] CRAN (R 4.1.3)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.1.3)
#>  xfun          0.29    2021-12-14 [1] CRAN (R 4.1.2)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.1.0)
#> 
#>  [1] C:/Users/PC/Documents/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.2/library
#> 
#> ------------------------------------------------------------------------------

I may be missing something, but it seems to me to be an issue.

Regards

VincentGuyader avatar Aug 29 '22 19:08 VincentGuyader

This is a consequence of the fact that formats are trained on a subset of the vector for efficiency reasons. A well known an documented issue

I think the training set should be selected from non-missing values only. Let me think about it a bit.

vspinu avatar Oct 20 '22 20:10 vspinu