[Rd] LC_TIME not set correctly by Sys.setlocale() ?
Joris Meys
jorismeys at gmail.com
Fri Jun 23 16:35:49 CEST 2017
Related to the following question on Stackoverflow:
https://stackoverflow.com/questions/44723690/unexpected-behavior-of-sys-setlocale#44723690
It appears as if Sys.setlocale() does not update LC_TIME correctly for use
in date formatting. Although R reports that LC_TIME is changed to the new
setting after use of Sys.setlocale(), as.Date() still uses the old
settings. The only way to update this is by specifically using LC_TIME.
Is this a bug or am I overlooking something?
Example:
> Sys.setlocale(locale = "French_Belgium")
[1]
"LC_COLLATE=French_Belgium.1252;LC_CTYPE=French_Belgium.1252;LC_MONETARY=French_Belgium.1252;LC_NUMERIC=C;LC_TIME=French_Belgium.1252"
> date <- "Dec-11"
> as.Date(date, format = "%b-%d")
[1] NA # expected
> Sys.setlocale(locale = "English_United Kingdom")
[1] "LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
Kingdom.1252;LC_MONETARY=English_United
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252"
> as.Date(date, format = "%b-%d")
[1] NA # not expected, should be a correct date
> Sys.setlocale("LC_TIME", "English_United Kingdom")
[1] "English_United Kingdom.1252"
> as.Date(date, format = "%b-%d")
[1] "2017-12-11" # expected
> Sys.setlocale(locale = "French_Belgium")
[1]
"LC_COLLATE=French_Belgium.1252;LC_CTYPE=French_Belgium.1252;LC_MONETARY=French_Belgium.1252;LC_NUMERIC=C;LC_TIME=French_Belgium.1252"
> as.Date(date, format = "%b-%d")
[1] "2017-12-11" # not expected, should be NA
> Sys.setlocale("LC_TIME", "French_Belgium")
[1] "French_Belgium.1252"
> as.Date(date, format = "%b-%d")
[1] NA # expected
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=French_Belgium.1252 LC_CTYPE=French_Belgium.1252
[3] LC_MONETARY=French_Belgium.1252 LC_NUMERIC=C
[5] LC_TIME=French_Belgium.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.0.3
loaded via a namespace (and not attached):
[1] compiler_3.4.0 R6_2.2.1 htmltools_0.3.6 tools_3.4.0
Rcpp_0.12.10
[6] digest_0.6.12 xtable_1.8-2 httpuv_1.3.3 mime_0.5
--
Joris Meys
Statistical consultant
Ghent University
Faculty of Bioscience Engineering
Department of Mathematical Modelling, Statistics and Bio-Informatics
tel : +32 (0)9 264 61 79
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
[[alternative HTML version deleted]]
More information about the R-devel
mailing list