tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
728 stars 207 forks source link

Format argument of `lubridate::as_date` doesn't work with non-standard date string in Lubridate 1.9.0. #1097

Closed colinbrust closed 1 year ago

colinbrust commented 1 year ago

In Lubridate 1.9.0, supplying a custom format string to as_date raises an error if a character is not prefixed by a "%". In the reprex below, a standard YYYY-MM-DD date string works, but adding any additional characters to the string raises an error. The same date conversion works with base R's as.Date:

lubridate::as_date("test2022-01-01", format="test%Y-%m-%d")
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as_date': Unknown formats supplied: tet
lubridate::as_date("2022-01-01", format="%Y-%m-%d")
#> [1] "2022-01-01"
as.Date("test2022-01-01", format="test%Y-%m-%d")
#> [1] "2022-01-01"

Here is my session info:

sessionInfo()
#> R version 4.2.1 (2022-06-23)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.1 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] rstudioapi_0.14   knitr_1.40        magrittr_2.0.3    timechange_0.1.1 
#>  [5] R.cache_0.16.0    rlang_1.0.6       fastmap_1.1.0     fansi_1.0.3      
#>  [9] stringr_1.4.1     styler_1.7.0      highr_0.9         tools_4.2.1      
#> [13] xfun_0.32         R.oo_1.25.0       utf8_1.2.2        cli_3.4.1        
#> [17] withr_2.5.0       htmltools_0.5.3   yaml_2.3.5        digest_0.6.30    
#> [21] tibble_3.1.8      lifecycle_1.0.3   purrr_0.3.5       R.utils_2.12.0   
#> [25] vctrs_0.5.1       fs_1.5.2          glue_1.6.2        evaluate_0.16    
#> [29] rmarkdown_2.16    reprex_2.0.2      stringi_1.7.8     compiler_4.2.1   
#> [33] pillar_1.8.1      generics_0.1.3    R.methodsS3_1.8.2 lubridate_1.9.0  
#> [37] pkgconfig_2.0.3

Created on 2022-11-16 with reprex v2.0.2

vspinu commented 1 year ago

Thanks! Was a bug introduced when dealing with #1042.