[R-SIG-Mac] as.Date() does not work with format %B
Milan Bouchet-Valat
nalimilan at club.fr
Sat Jun 9 11:17:38 CEST 2012
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! ;-)
More information about the R-SIG-Mac
mailing list