as.Date() does not work with format %B
Not that this is at all likely to be helpful, but it seems to be month dependent in my locale:
strftime("1998-07-09", "%d %B %Y")
[1] "09 July 1998"
as.Date("09 July 1998", "%d %B %Y")
[1] "1998-07-09"
Sys.getlocale()
[1] "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8" # Now switch to france
Sys.setlocale("LC_TIME", "fr_FR.UTF-8")
[1] "fr_FR.UTF-8"
strftime("1998-07-09", "%d %B %Y")
[1] "09 juillet 1998"
as.Date("09 juillet 1998", "%d %B %Y")
[1] NA
as.Date("09 avril 1998", "%d %B %Y")
[1] "1998-04-09" and more generally
as.Date(strftime(paste("1998",1:12,"09", sep = "-"), "%d %B %Y"), "%d %B %Y")
[1] "1998-01-09" "1998-02-09" "1998-03-09" "1998-04-09" "1998-05-09" [6] "1998-06-09" NA "1998-08-09" "1998-09-09" "1998-10-09" [11] "1998-11-09" "1998-12-09"
Sys.setlocale("LC_TIME", "en_US.UTF-8")
sessionInfo()
R version 2.15.0 (2012-03-30) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] graphics grDevices utils datasets compiler stats methods [8] base other attached packages: [1] lattice_0.20-6 ggplot2_0.9.1 quantmod_0.3-18 TTR_0.21-1 [5] xts_0.8-7 zoo_1.7-7 Defaults_1.1-1 loaded via a namespace (and not attached): [1] colorspace_1.1-1 dichromat_1.2-4 digest_0.5.2 grid_2.15.0 [5] labeling_0.1 MASS_7.3-18 memoise_0.1 munsell_0.3 [9] plyr_1.7.1 proto_0.3-9.2 RColorBrewer_1.0-5 reshape2_1.2.1 [13] scales_0.2.1 stringr_0.6 Not sure why that would be though... Michael
On Sat, Jun 9, 2012 at 4:17 AM, Milan Bouchet-Valat <nalimilan at club.fr> wrote:
Hi! I currently experience a problem with my package tm.plugin.factiva on Macs. I need to parse a locale-dependent date string into a proper Date object. It works fine on Linux and Windows, but on a Mac I've tested, parsing dates containing the %B format (for full month name) does not work. It's very easy to reproduce (here in French, but it's straightforward to adapt it to your locale):
# Check that formatting dates works: OK
strftime("1998-07-09", "%d %B %Y")
[1] "09 juillet 1998"
# Try to convert the same string to a date: FAIL
as.Date("9 juillet 1998", format="%d %B %Y")
[1] NA
as.Date("09 juillet 1998", format="%d %B %Y")
[1] NA The locale looks good:
Sys.getlocale()
[1] "fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8" And setting LC_TIME manually does not change anything:
Sys.setlocale("LC_TIME", "fr_FR.UTF-8")
[1] "fr_FR.UTF-8"
as.Date("9 juillet 1998", "%d %B %Y")
[1] NA FWIW, I've also tried using strptime() instead of as.Date(), and the problem is the same. This is with R 2.15.0 on Mac OS 10.6.8.
sessionInfo()
R version 2.15.0 (2012-03-30) Platform: i386-apple-darwin9.8.0/i386 (32-bit) locale: [1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8 attached base packages: [1] stats ? ? graphics ?grDevices utils ? ? datasets ?methods ? base Any clues much appreciated! ;-)
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac