3

I have a Problem with setting the abbreviation of weekdays in some time Data. What I need are the abbreviations "Mon, Tues, Wed, Thurs, Fri, Sat, Sun". The lubridate::wday() function I work with gives the values "Mon, Tue, Wed, Thu, Fri, Sat, Sun".

It's a small difference for the days "Tuesday" and "Thursday".

x <- seq(Sys.Date() - 7, Sys.Date(), by = 1)
lubridate::wday(x, label = TRUE)
## [1] Thu Fri Sat Sun Mon Tue Wed Thu

I also changed the language-settings with locale, but this didn't do the trick because I'm not sure about the possible parameters to set (possible selections).

lubridate::wday(x, label = TRUE, locale = "French")
## [1] jeu\\. ven\\. sam\\. dim\\. lun\\. mar\\. mer\\. jeu\\.

lubridate::wday(x, label = TRUE, locale = "English")
## [1] Thu Fri Sat Sun Mon Tue Wed Thu

lubridate::wday(x, label = TRUE, locale = "English_Great Britain")
## [1] Thu Fri Sat Sun Mon Tue Wed Thu

lubridate::wday(x, label = TRUE, locale = "English_United States")
## [1] Thu Fri Sat Sun Mon Tue Wed Thu

The Difference might come from a change in my R Version (Now 3.4.2), as there was mentioned a change in this new Version concerning this subject... (https://cran.r-project.org/bin/windows/base/NEWS.R-3.4.2.html --> Setting the LC_ALL category in Sys.setlocale() invalidates any cached locale-specific day/month names and the AM/PM indicator for strptime() (as setting LC_TIME has since R 3.1.0)

System - Information:

R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

loaded via a namespace (and not attached):
 [1] compiler_3.4.2  imsbasics_1.8.0 magrittr_1.5    tools_3.4.2     simtimer_2.0.18 Rcpp_0.12.12    lubridate_1.7.1
 [8] schedule_1.0.0  stringi_1.1.5   stringr_1.2.0  
MichiSmith
  • 317
  • 1
  • 7

1 Answers1

5

Since you want non-standard abbreviations, you'll need to do it manually:

x <- seq(Sys.Date() - 7, Sys.Date(), by = 1)
Sys.setlocale("LC_TIME", "C") #since I'm at a non-English locale
factor(weekdays(x, TRUE), 
       levels = c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"),
       labels = c("Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"))
#[1] Thurs Fri   Sat   Sun   Mon   Tues  Wed   Thurs
#Levels: Mon Tues Wed Thurs Fri Sat Sun

I'm not sure why you believe this to be related to R versions ...

Roland
  • 127,288
  • 10
  • 191
  • 288
  • 1
    How can i make this the default setting? Do you have any idea why this abbreviations ("Mon, Tues, Wed, Thurs, Fri, Sat, Sun") are the default setting on my friends computer, which uses exactly the same OS, Setup, R-Version, ...? To your question - I'm searching in the dark... ;) Any help is highly appreciated. – MichiSmith Nov 09 '17 at 13:16
  • I'm not aware of any locale abbreviating "Tuesday" as "Tues" and I can't find one in [this list](https://lh.2xlibre.net/values/abday/) either. – Roland Nov 09 '17 at 13:51
  • 1
    Older versions of `lubridate` hard-coded the long and abbr names inside the function. They were only "english" ones and they used that non-standard locale convention for `Tues` and `Thurs`. Like @Roland, I no of no locale with those alternate abbreviations. – hrbrmstr Nov 09 '17 at 13:55