2

This:

base::as.Date("07 Mar 2025", tryFormats ="%d %b %Y")

returns:

Error in charToDate(x) : 
  character string is not in a standard unambiguous format

I'm using R 3.6.2 and sessioninfo returns:

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3 LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=de_BE.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=de_BE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=de_BE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=de_BE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.2
user189035
  • 5,589
  • 13
  • 52
  • 112
  • works for me `base::as.Date("07 Mar 2025", tryFormats ="%d %b %Y")` I am on R 3.6.1. I am not sure if anything changed. – Ronak Shah Jan 06 '20 at 10:36
  • What is the value of LC_TIME for your system? If it's not English, as.Date might not understand Mar. You can check with Sys.getlocale() . – WaltS Jan 06 '20 at 12:59

1 Answers1

1

It is because of your locale, the month abbreviations are different.

In my UK locale:

Sys.getlocale("LC_TIME")
[1] "English_United Kingdom.1252"
base::as.Date("07 Mar 2025", tryFormats ="%d %b %Y")
[1] "2025-03-07"

In a German-speaking Belgian locale:

Sys.setlocale("LC_TIME","German_Belgium.1252")
[1] "German_Belgium.1252"
base::as.Date("07 Mar 2025", tryFormats ="%d %b %Y")
Error in charToDate(x) : 
  character string is not in a standard unambiguous format

base::as.Date("07 Mrz 2025", tryFormats ="%d %b %Y")
[1] "2025-03-07"
base::as.Date("07 März 2025", tryFormats ="%d %b %Y")
[1] "2025-03-07"

You could try switching to an English locale to interpret the data using Sys.setlocale. Note that the 1252 ones are Windows-specific, you would probably need to use something like en_GB.UTF-8 in Linux.

James
  • 65,548
  • 14
  • 155
  • 193